Store
This is an equivalent of Redux store. However, there are a few differences:
Instead of getState there is a currentState property that returns current state.
State changes are received by collecting state.
Contains closure field that provides a mechanism to inject objects to the store and make them available to middlewares.
To create an instance use buildStore (recommended) or Store() function.
Functions
This is equivalent to Redux dispatch.
Properties
There is no equivalent to this in original Redux. It provides a current DispatchClosure. It remains immutable. However, elements inside might mutate depending on their implementation.
Extensions
Returns CoroutineScope associated with a store.
Dispatches action and expects any middleware to launch a single foreground job logically associate with it. Coroutine is launched in a scope provided by DispatchCoroutineScope.
Dispatches action and expects any middleware to launch a single foreground job logically associate with it. This function suspends until foreground job is finished. When coroutine that calls this function is cancelled, foreground job is also cancelled.
Maps Store.state to a new StateFlow using given selector function. selector function is not called before selected state is actually accessed using StateFlow.value or collected. Also, it's not called if state is not changed. State is compared using equals so selection might be recalculated even if unrelated part of the state changed. However, if selection stays the same (again compared using equals), it's not emitted (just like every StateFlow). To optimize state selection, use select
with Selector param.
Maps Store.state to a new StateFlow using given selector. Selector function is called only if Selector.isStateEqual returns false (by default it refers to equals). Also, selector function is not called before selected state is actually accessed using StateFlow.value or collected. Selector result is emitted only if Selector.isSelectionEqual returns false (by default it refers to equals).
Runs given block as a coroutine in DispatchScope.coroutineScope. Effectively it ensures that any operation on a DispatchScope inside a block runs on proper thread.
Adds local changes to LocalClosureContainer with a given closure for a time of block execution.