reduce method

Parent? reduce(
  1. Parent parentState,
  2. ReduxAction action
)

Retrieves the fitting reducer for the ReduxAction supplied, executes it and returns the Parent or null if no ReducerFunction was found in its reducers or within its children The first ReducerFunction that is found is used and the result returned immediately. You should never have multiple ReducerFunctions defined for any ReduxAction!

Implementation

Parent? reduce(Parent parentState, ReduxAction action) {
  ClassType state = getter(parentState);

  Iterable<ActionReducer> result = reducers.where((element) => element.action == action.runtimeType);

  ActionReducer? actionReducer = result.isNotEmpty ? result.first : null;

  if (actionReducer != null) {
    return setter(parentState, actionReducer.call(state, action.value));
  }

  for (ReduxReducer<ClassType, dynamic> childReducer in children) {
    ClassType? newChildState = childReducer.reduce(state, action);

    if (newChildState != null) {
      return setter(parentState, newChildState);
    }
  }
}