add handleActions redux util
This commit is contained in:
parent
af43f284e3
commit
6fdc5b7c7d
1 changed files with 10 additions and 0 deletions
10
ui/js/util/redux-utils.js
Normal file
10
ui/js/util/redux-utils.js
Normal 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);
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in a new issue