lbry-desktop/ui/js/util/redux-utils.js

11 lines
397 B
JavaScript
Raw Normal View History

2017-11-27 18:07:57 +01:00
// 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);
};
};