@state-sync/redux-path-reducer
Version:
state-sync client only json path reducer
32 lines (31 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var Patch_1 = require("./Patch");
function PatchReducer(initialState, reducers) {
return function (state, action) {
// initialization
if (state === undefined)
return reducers.call(undefined, initialState);
// sync
try {
var fit = action.type.indexOf('@STATE_SYNC/') === 0;
if (fit) {
switch (action.type) {
case '@STATE_SYNC/PATCH_REDUCE': {
try {
return new Patch_1.Patch(action.payload).apply(state);
}
catch (e) {
console.error('Patch failed', state, action.payload);
}
}
}
}
}
catch (e) {
console.error('action failed:', action, e);
}
return reducers.call(undefined, state);
};
}
exports.PatchReducer = PatchReducer;