UNPKG

mst-effect

Version:

Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.

26 lines (25 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.subscribe = void 0; const operators_1 = require("rxjs/operators"); const const_1 = require("../const"); function subscribe(self, factory, actions$) { if (!self[const_1.EFFECT_ACTIONS_HANDLER]) { console.warn(`[mst-effect]: Make sure the 'types' is imported from 'mst-effect' instead of 'mobx-state-tree'`); } return actions$ .pipe((0, operators_1.tap)((actions) => { var _a; return (_a = self[const_1.EFFECT_ACTIONS_HANDLER]) === null || _a === void 0 ? void 0 : _a.call(self, actions); }), logAngIgnoreError(factory)) .subscribe(); function logAngIgnoreError(factory) { return (0, operators_1.catchError)((err, caught) => { /* eslint-disable no-console */ console.group('[mst-effect]: error'); console.log(factory); console.error(err); console.groupEnd(); /* eslint-enable no-console */ return caught; }); } } exports.subscribe = subscribe;