add method
Adds reduce
or effect
into the system.
If we adds reduce
or effect
multiple times, the call side order is in serial.
Usage Example
Below code showed how adds reduce
or effect
into system:
counterSystem
...
.add(reduce: (state, event) {
if (event is Increment) return state + 1;
return state;
})
.add(reduce: (state, event) {
if (event is Decrement) return state - 1;
return state;
})
.add(effect: (state, oldState, event, dispatch) {
// effect - log update
print('\nEvent: $event');
print('OldState: $oldState');
print('State: $state');
})
...
Implementation
System<State, Event> add({
Reduce<State, Event>? reduce,
Effect<State, Event>? effect,
}) => withContext<void>(
createContext: () {},
reduce: reduce,
effect: effect == null ? null : (context, state, oldState, event, dispatch) {
effect(state, oldState, event, dispatch);
}
);