UNPKG

453 BJavaScriptView Raw
1/* @flow */
2type ActionHandler<T> = (state: T, action: Action<{ [string]: any }>) => T;
3
4type ActionHandlers<T> = { [string]: ActionHandler<T> };
5
6export default function createReducer<T>(initialState: T, actionHandlers: ActionHandlers<T>) {
7 return (state: T = initialState, action: Action<any>): T => {
8 return actionHandlers.hasOwnProperty(action.type)
9 ? actionHandlers[action.type](state, action)
10 : state;
11 };
12}