createReducer<State> function Null safety

Reducer<State> createReducer<State>(
  1. Iterable<On<State, StoreAction>> ons
)

A utility function that combines several On reducer objects.

Example

Reducer<int> counterReducer = createReducer([
  On<int, IncrementCounterAction>(
    (counter, action) => counter + 1,
  ),
  On<int, DecrementCounterAction>(
    (counter, action) => counter - 1,
  ),
]);

Implementation

Reducer<State> createReducer<State>(
  Iterable<On<State, StoreAction>> ons,
) {
  return (State state, StoreAction action) {
    for (final onAction in ons) {
      state = onAction(state, action);
    }
    return state;
  };
}