1234567891011121314151617 |
- import {cowValueModel} from './cow-value-model';
- export const subReducer = (key, reducer, ...otherKeys) => {
- const {get: getValue, set: setValue} = cowValueModel(key),
- otherParts = otherKeys.map(each => cowValueModel(each).get);
- return (state, action) => {
- let newSubState = reducer(getValue(state), action, ...otherParts.map(getValue => getValue(state)));
- if (typeof newSubState === "undefined") {
- throw new Error(`The '${key}' reducer must not return undefined.`);
- }
- return setValue(state, newSubState);
- };
- };
- export const composeReducers = (...reducers) => (state, action) =>
- reducers.reduce((x, r) => r(x, action), state);
|