combineReducers<State> function

Reducer<State> combineReducers <State>(
  1. Iterable<Reducer<State>> reducers
)

Defines a utility function that combines several reducers.

In order to prevent having one large, monolithic reducer in your app, it can be convenient to break reducers up into smaller parts that handle more specific functionality that can be decoupled and easily tested.

Example

helloReducer(state, action) {
    return "hello";
}

friendReducer(state, action) {
  return state + " friend";
}

final helloFriendReducer = combineReducers(
  helloReducer,
  friendReducer,
);

Implementation

Reducer<State> combineReducers<State>(Iterable<Reducer<State>> reducers) {
  return (State state, dynamic action) {
    for (final reducer in reducers) {
      state = reducer(state, action);
    }
    return state;
  };
}