Store<S extends StoreState> constructor
Store<S extends StoreState> ({})
Implementation
Store({
required S initialState,
this.reducer,
this.effects,
}) {
state.add(initialState);
if (reducer != null) {
_actionStream.listen((StoreAction action) {
S newState = reducer!(state.value, action);
state.add(newState);
_effectsActionStream.add(action);
});
}
if (effects != null) {
for (var effect in effects!) {
effect(_effectsActionStream, this).listen((effectResult) {
if (effectResult is StoreAction) {
dispatch(effectResult);
}
if (effectResult is List &&
effectResult.every((element) => element is StoreAction)) {
for (var action in effectResult) {
dispatch(action);
}
}
});
}
}
}