StoreAccessor

abstract class StoreAccessor(scope: CoroutineScope) : CoroutineScope(source)

Provides access to dispatch, state selection, and logic selection.

StoreAccessor is passed to Logic classes during construction, allowing them to dispatch actions, read state from other modules, and access other Logic instances.

Example:

class OrderLogic(private val storeAccessor: StoreAccessor) : ModuleLogic() {
suspend fun placeOrder(order: Order) {
// Dispatch an action
storeAccessor.dispatch(OrderAction.SetProcessing(true))

// Read state from another module
val userState = storeAccessor.selectState<UserState>().first()

// Access another module's logic
val paymentLogic = storeAccessor.selectLogic<PaymentLogic>()
paymentLogic.processPayment(order.total)
}
}

Inheritors

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope)

Properties

Link copied to clipboard
Link copied to clipboard
abstract val dispatch: Dispatch

The dispatch function for sending actions to the store. This is fire-and-forget - it returns immediately without waiting for processing.

Functions

Link copied to clipboard
abstract fun addCrashListener(listener: CrashListener)

Registers a CrashListener to be notified when logic invocation throws.

Link copied to clipboard

Provides access to internal store operations for specialized use cases.

Link copied to clipboard
abstract suspend fun dispatchAndAwait(action: ModuleAction): DispatchResult

Dispatch an action and wait for it to be processed. Returns a DispatchResult indicating whether the action was applied or blocked.

Link copied to clipboard
abstract suspend fun getLogicForModule(module: Module<*, *>): ModuleLogic?

Returns the logic instance for the given module, suspending until the store is fully initialized.

Link copied to clipboard
inline fun <M : Any> getModule(): M?

Convenience reified overload for getModule.

abstract fun <M : Any> getModule(moduleClass: KClass<M>): M?

Get a module instance by its class.

Link copied to clipboard
abstract fun getRegisteredModules(): List<Module<*, *>>

Returns all modules registered in this store.

Link copied to clipboard
abstract fun getStateFlowForModule(module: Module<*, *>): StateFlow<ModuleState>?

Returns the StateFlow for the given module's state, or null if the module is not registered in this store.

Link copied to clipboard
abstract fun removeCrashListener(listener: CrashListener)

Removes a previously registered CrashListener.

Link copied to clipboard
abstract suspend fun reset(): Boolean

Resets the store by cancelling all child coroutines and restarting action processing.

Link copied to clipboard
abstract fun resetAsync(): Job

Non-suspend convenience function that resets the store asynchronously.

Link copied to clipboard
abstract suspend fun <L : ModuleLogic> selectLogic(logicClass: KClass<L>): L

Select a module's logic instance by its class.

Link copied to clipboard
inline suspend fun <L : ModuleLogic> StoreAccessor.selectLogic(): L

Selects a module's logic instance by its type.

Link copied to clipboard
abstract suspend fun <S : ModuleState> selectState(stateClass: KClass<S>): StateFlow<S>

Select a module's state flow by its class.

Link copied to clipboard
inline suspend fun <S : ModuleState> StoreAccessor.selectState(): StateFlow<S>

Selects a module's state flow by its type.