Store< State> constructor
Store< State>(
- Reducer<
State> reducer, - {required State initialState,
- List<
Middleware< State>> middleware = const [], - bool syncStream = false,
- bool distinct = false}
Creates an instance of a Redux Store.
The reducer argument specifies how the state should be changed in response to dispatched actions.
The optional initialState
argument defines the State of the store when
the Store is first created.
The optional middleware
argument takes a list of Middleware functions
or MiddlewareClass. See the Middleware documentation for information
on how they are used.
The syncStream
argument allows you to use a synchronous
StreamController instead of an async StreamController
under the hood.
By default, the Stream is async.
Implementation
Store(
this.reducer, {
required State initialState,
List<Middleware<State>> middleware = const [],
bool syncStream = false,
/// If set to true, the Store will not emit onChange events if the new State
/// that is returned from your [reducer] in response to an Action is equal
/// to the previous state.
///
/// Under the hood, it will use the `==` method from your State class to
/// determine whether or not the two States are equal.
bool distinct = false,
}) : _changeController = StreamController.broadcast(sync: syncStream) {
_state = initialState;
_dispatchers = _createDispatchers(
middleware,
_createReduceAndNotify(distinct),
);
}