WrapReduce<St> class Null safety

You may globally wrap the reducer to allow for some pre or post-processing. Note: if the action also have a ReduxAction.wrapReduce method, this global wrapper will be called AFTER (it will wrap the action's wrapper which wraps the action's reducer).

If ifShouldProcess is overridden to return false, the wrapper will be turned of.

The process method gets the old-state and the new-state, and returns the end state that you want to send to the store. Note: In sync reducers, the old-state is the state before the reducer is called. However, in async reducers, the old-state is the state AFTER the reducer returns but before the reducer's result is committed to the store.

For example, this wrapper checks if newState.someInfo is out of range, and if that's the case it's logged and changed to some valid value:

class MyWrapReduce extends WrapReduce<AppState> {
  St process({required St oldState, required St newState}) {
    if (identical(newState.someInfo, oldState.someInfo) || oldState.someInfo.isWithRange())
    return newState;
    else {
      Logger.log('Invalid value: ${oldState.someInfo}');
      return newState.copy(someInfo: newState.someInfo.copy(SomeInfo(validValue)));
      }}}

Note the wrapReduce method encapsulates the complexities of differentiating sync and async reducers. However, you can override it to provide your own implementation if necessary.

Constructors

WrapReduce()

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

ifShouldProcess() bool
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
process({required St oldState, required St newState}) → St
toString() String
A string representation of this object. [...]
inherited
wrapReduce(Reducer<St> reduce, Store<St> store) Reducer<St>

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited