1 | /* @flow */
|
2 | type ActionHandler<T> = (state: T, action: Action<{ [string]: any }>) => T;
|
3 |
|
4 | type ActionHandlers<T> = { [string]: ActionHandler<T> };
|
5 |
|
6 | export 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 | }
|