UNPKG

typedux

Version:

Slightly adjusted Redux (awesome by default) for TS

25 lines 787 B
/** * Create a simple mapped reducer fn * * @param propertyKey * @param args * @returns {function(S, M): S} */ export function makeMappedReducerFn(propertyKey, args) { return (state, message) => { let stateFn = state[propertyKey]; if (!stateFn) throw new Error(`Unable to find mapped reduce function on state ${propertyKey}`); if (state && typeof state.withMutation === 'function') { const newState = state.withMutation(tempState => { tempState = tempState[propertyKey](...args); return tempState; }); return ((newState === state) ? state : newState); } else { return stateFn(...args); } }; } //# sourceMappingURL=ActionMapper.js.map