wrapReduce method

Reducer<St> wrapReduce(
  1. Reducer<St> reduce
)

You may wrap the reducer to allow for some pre- or post-processing. For example, if you want to prevent an async reducer to change the current state, if the current state has already changed since when the reducer started:

Reducer<St> wrapReduce(Reducer<St> reduce) => () async {
   var oldState = state;
   AppState? newState = await reduce();
   return identical(oldState, state) ? newState : null;
};

Note: If you return a function that returns a Future, the action will be ASYNC. If you return a function that returns St, the action will be SYNC only if the before and reduce methods are also SYNC.

Implementation

Reducer<St> wrapReduce(Reducer<St> reduce) => reduce;