lbry-desktop/src/renderer/util/redux-utils.js

18 lines
532 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
const handleActions = (actionMap, defaultState) => (state = defaultState, action) => {
2017-12-13 22:36:30 +01:00
const handler = actionMap[action.type];
2017-12-08 21:14:35 +01:00
2017-12-13 22:36:30 +01:00
if (handler) {
const newState = handler(state, action);
return Object.assign({}, state, newState);
}
2017-12-08 21:14:35 +01:00
2017-12-13 22:36:30 +01:00
// just return the original state if no handler
// returning a copy here breaks redux-persist
return state;
2017-11-27 18:07:57 +01:00
};
export { handleActions as default };