Reducer
- The Reducer is a context-independent pure function. It receives the following parameters
- It mainly contains three aspects of information
- Receive an “intent” and make a state modification.
- If you want to modify the state, you need to create a new copy and modify it on the copy.
- If the small state is modified, it will automatically trigger the copy of the main state’s layers data, and then notify the components to refresh in a flattened manner.
- Sample Code
Reducer<String> buildMessageReducer() {
return asReducer(<Object, Reducer<String>>{
'shared': _shared,
});
}
String _shared(String msg, Action action) {
return '$msg [shared]';
class MessageComponent extends Component<String> {
view: buildMessageView,
effect: buildEffect(),
reducer: buildMessageReducer(),
);
}