Merge pull request #789 from lbryio/util

add handleActions redux util
This commit is contained in:
Jeremy Kauffman 2017-11-27 12:34:14 -05:00 committed by GitHub
commit a8529ea8b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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);
};
};