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
|
2017-12-21 18:32:51 +01:00
|
|
|
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
|
|
|
};
|
2017-12-21 18:32:51 +01:00
|
|
|
|
|
|
|
export { handleActions as default };
|