Store<State> class
Creates a Redux store that holds the app state tree.
The only way to change the state tree in the store is to dispatch an action. the action will then be intercepted by any provided Middleware. After running through the middleware, the action will be sent to the given Reducer to update the state tree.
To access the state tree, call the state getter or listen to the onChange stream.
Basic Example
// Create a reducer
final increment = 'INCREMENT';
final decrement = 'DECREMENT';
int counterReducer(int state, action) {
switch (action) {
case increment:
return state + 1;
case decrement:
return state - 1;
default:
return state;
}
}
// Create the store
final store = new Store<int>(counterReducer, initialState: 0);
// Print the Store's state.
print(store.state); // prints "0"
// Dispatch an action. This will be sent to the reducer to update the
// state.
store.dispatch(increment);
// Print the updated state. As an alternative, you can use the
// `store.onChange.listen` to respond to all state change events.
print(store.state); // prints "1"
Constructors
Properties
- hashCode → int
-
The hash code for this object.
read-onlyinherited
-
onChange
→ Stream<
State> -
A stream that emits the current state when it changes.
read-only
-
reducer
↔ Reducer<
State> -
The Reducer for your Store. Allows you to get the current reducer or
replace it with a new one if need be.
read / write
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
- state → State
-
Returns the current state of the app
read-only
Methods
-
dispatch(
dynamic action) → dynamic - Runs the action through all provided Middleware, then applies an action to the state using the given Reducer. Please note: Middleware can intercept actions, and can modify actions or stop them from passing through to the reducer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
teardown(
) → Future - Closes down the Store so it will no longer be operational. Only use this if you want to destroy the Store while your app is running. Do not use this method as a way to stop listening to onChange state changes. For that purpose, view the onChange documentation.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited