reactState method
Add effect
triggered by reacting to whole state change.
API Overview
system
...
.reactState(
equals: (it1, it2) { // `equals` is used to determine if old state equals
return it1 == it2; // to new state. If there are not equal, then effect
}, // is triggered. `equals` is nullable, defaults to
// `==` as shown.
skipInitialState: true, // return true if initial state is skipped,
// which won't trigger effect.
// return false if initial state isn't skipped,
// which will trigger effect.
// `skipInitialState` defaults to true if omitted.
effect: (state, dispatch) {
// trigger effect here with new state, required
},
)
...
Usage Example
Below code showed how to save state when state changed.
system
...
.reactState(
effect: (state, dispatch) async {
await storage.save(state);
},
)
...
Implementation
System<State, Event> reactState({
Equals<State>? equals,
bool skipInitialState = true,
required void Function(State state, Dispatch<Event> dispatch) effect,
}) => react<State>(
value: (state) => state,
equals: equals,
skipInitialValue: skipInitialState,
effect: effect
);