dispatch/client/js/utils/createReducer.js

12 lines
327 B
JavaScript
Raw Normal View History

2018-04-25 03:36:27 +00:00
import produce from 'immer';
import has from 'lodash/has';
2015-12-28 23:34:32 +00:00
export default function createReducer(initialState, handlers) {
return function reducer(state = initialState, action) {
2018-04-25 03:36:27 +00:00
if (has(handlers, action.type)) {
return produce(state, draft => handlers[action.type](draft, action));
2015-12-28 23:34:32 +00:00
}
return state;
};
}