Reducer

    • The Reducer is a context-independent pure function. It receives the following parameters
      • T state
      • Action action
    • 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
    1. Reducer<String> buildMessageReducer() {
    2. return asReducer(<Object, Reducer<String>>{
    3. 'shared': _shared,
    4. });
    5. }
    6. String _shared(String msg, Action action) {
    7. return '$msg [shared]';
    8. class MessageComponent extends Component<String> {
    9. view: buildMessageView,
    10. effect: buildEffect(),
    11. reducer: buildMessageReducer(),
    12. );
    13. }