wrapReduce method
You may override wrapReduce to wrap the reduce method and allow for
some pre- or post-processing. For example, if you want to prevent an
async reducer to change the current state in cases where the current
state has already changed since when the reducer started:
Future<St?> wrapReduce(Reducer<St> reduce) async {
var oldState = state;
AppState? newState = await reduce();
return identical(oldState, state) ? newState : null;
};
IMPORTANT:
-
Your wrapReduce method MUST always return
Future<St?>. If it returns aFutureOr, it will NOT be called, and no error will be shown. This is because AsyncRedux uses the return type to determine if wrapReduce was overridden or not. -
If wrapReduce returns
StorSt?, an error will be thrown. -
Once you override wrapReduce the action will always be ASYNC, regardless of the before and
reducemethods.
See mixins Retry, Throttle, and Debounce for real wrapReduce examples.
Implementation
@protected
FutureOr<St?> wrapReduce(Reducer<St> reduce) {
return null;
}