UNPKG

@nteract/myths

Version:

A redux-observable framework for better locality of dependencies

20 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMakeRootEpic = exports.makeEpics = void 0; const redux_observable_1 = require("redux-observable"); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const makeEpic = (pkg, myth, dispatch, filterBy) => (action$, state$) => action$.pipe(filterBy, operators_1.withLatestFrom(state$.pipe(operators_1.map(state => state.__private__[pkg]))), operators_1.mergeMap(([action, state]) => { var _a; return (_a = dispatch(action, state, myth)) !== null && _a !== void 0 ? _a : rxjs_1.EMPTY; })); exports.makeEpics = (pkg, myth, definition) => { var _a, _b; const epics = []; for (const { when, dispatch } of (_a = definition.andAlso) !== null && _a !== void 0 ? _a : []) { epics.push(makeEpic(pkg, myth, dispatch, operators_1.filter(when))); } for (const dispatch of (_b = definition.thenDispatch) !== null && _b !== void 0 ? _b : []) { epics.push(makeEpic(pkg, myth, dispatch, redux_observable_1.ofType(myth.type))); } return epics; }; exports.makeMakeRootEpic = (myths) => () => redux_observable_1.combineEpics(...Object.values(myths).map(myth => redux_observable_1.combineEpics(...myth.epics))); //# sourceMappingURL=epics.js.map