Store<S, A> class

The runtime that holds application state, processes actions through a Reducer, and executes Effects.

A Store is the central coordination point of the Composable Architecture. It maintains the current state, dispatches actions to the reducer, and manages the lifecycle of effects (including cancellation).

Creating a Store

// With an environment (API clients, services, etc.)
final store = Store.initial(AppState(), appReducer, AppEnvironment());

// Without an environment
final store = Store.emptyEnvironment(0, counterReducer);

Dispatching Actions

store.send(CounterAction.increment);

Observing State

store.stateObservable.listen((state) => print(state));

Scoping

Create child stores that project a subset of state and actions:

final counterStore = appStore.scope(
  toLocalState: (appState) => appState.counter,
  toGlobalAction: (action) => AppAction.counter(action),
);

Properties

actionObservable Observable<A>
An Observable that emits each action as it is dispatched.
no setter
bufferedActions → ActionBuffer<A>
Buffer for actions dispatched during an active send cycle.
final
cancellableEffectHandler → CancellableEffectHandler
Manages registration and cancellation of in-flight effects.
final
hashCode int
The hash code for this object.
no setterinherited
reducer → ({Effect<A> effect, S state}) Function(S, A)
The compiled reducer function that processes state and actions.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state ↔ S
The current state held by this store.
getter/setter pair
stateObservable Observable<S>
An Observable that emits the current state whenever it changes.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scope<LocalState, LocalAction>({required LocalState toLocalState(S globalState), required A toGlobalAction(LocalAction localAction)}) Store<LocalState, LocalAction>
Creates a scoped child store that projects a subset of state and actions.
scopeAction<LocalAction>({required A toGlobalAction(LocalAction localAction)}) Store<S, LocalAction>
Creates a scoped store that transforms only the action type, keeping the same state.
scopeState<LocalState>({required LocalState toLocalState(S)}) Store<LocalState, A>
Creates a scoped store that projects only the state, keeping the same action type.
send(A action) → void
Dispatches an action to the store's reducer.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

emptyEnvironment<S, A>(S initialState, Reducer<S, A, EmptyEnvironment> reducer) Store<S, A>
Creates a store for reducers that do not need an environment.
initial<S, A, Environment>(S initialState, Reducer<S, A, Environment> reducer, Environment environment) Store<S, A>
Creates a store with an environment that is closed over by the reducer.