UNPKG

mst-effect

Version:

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

14 lines (13 loc) 608 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.signal = void 0; const mobx_state_tree_1 = require("mobx-state-tree"); const rxjs_1 = require("rxjs"); function signal(self, fn) { var _a; const payloadSource = new rxjs_1.Subject(); const signal$ = (_a = fn === null || fn === void 0 ? void 0 : fn(payloadSource.asObservable())) !== null && _a !== void 0 ? _a : payloadSource.asObservable(); (0, mobx_state_tree_1.addDisposer)(self, () => payloadSource.complete()); return [signal$, (payload) => payloadSource.next(payload)]; } exports.signal = signal;