typedux
Version:
Slightly adjusted Redux (awesome by default) for TS
29 lines • 946 B
JavaScript
/**
* Create a simple mapped reducer fn
*
* @param propertyKey
* @param args
* @returns {function(S, M): S}
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeMappedReducerFn = void 0;
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);
}
};
}
exports.makeMappedReducerFn = makeMappedReducerFn;
//# sourceMappingURL=ActionMapper.js.map
;