add handleActions redux util

This commit is contained in:
Sean Yesmunt 2017-11-27 12:07:57 -05:00
parent af43f284e3
commit 6fdc5b7c7d

10
ui/js/util/redux-utils.js Normal file
View file

@ -0,0 +1,10 @@
// util for creating reducers
// based off of redux-actions
// https://redux-actions.js.org/docs/api/handleAction.html#handleactions
export const handleActions = (actionMap, defaultState) => {
return (state = defaultState, action) => {
const handler = actionMap[action.type];
const newState = handler ? handler(state, action) : {};
return Object.assign({}, state, newState);
};
};