@coorpacademy/squirrel
Version:
Local mirror mecanism for ETCD
27 lines (20 loc) • 750 B
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _fp = require("lodash/fp");
const eventReducer = (state, event) => {
if (event.value === undefined) return (0, _fp.unset)(event.key, state);else return (0, _fp.set)(event.key, event, state);
};
const createReducer$ = command$ => command$.filter(command => !!command && typeof command.type === 'string').scan((records, command) => {
switch (command.type) {
case 'fetch':
return (0, _fp.reduce)(eventReducer, {}, command.payload);
case 'watch':
return (0, _fp.reduce)(eventReducer, records, command.payload);
default:
return records;
}
}, {});
var _default = createReducer$;
exports.default = _default;
//# sourceMappingURL=reducer.js.map