UNPKG

oo-redux-utils2

Version:
30 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function createStateReducer(initialState, actionBaseClass, stateNamespace) { return function (currentState = initialState, reduxAction) { return (reduxAction.type instanceof actionBaseClass) && reduxAction.type.getStateNamespace() === stateNamespace ? reduxAction.type.perform(currentState) : currentState; }; } class OOReduxUtils { static mergeOwnAndForeignState(ownState, foreignState) { const overlappingOwnAndForeignStateKeys = Object.keys(ownState).filter((ownStateKey) => Object.keys(foreignState).includes(ownStateKey)); if (overlappingOwnAndForeignStateKeys.length > 0) { throw new Error('One or more overlapping properties in own and foreign state'); } return { ...ownState, ...foreignState }; } static createStateReducer(initialState, actionBaseClasses) { return createStateReducer(initialState, actionBaseClasses, ''); } static createNamespacedStateReducer(initialState, actionBaseClasses, stateNamespace) { return createStateReducer(initialState, actionBaseClasses, stateNamespace); } } exports.default = OOReduxUtils; //# sourceMappingURL=OOReduxUtils.js.map