UNPKG

@react-mvi/testing

Version:

Test module for React MVI.

53 lines (52 loc) 1.92 kB
"use strict"; /** * @fileoverview * @author Taketoshi Aono */ Object.defineProperty(exports, "__esModule", { value: true }); var rxjs_1 = require("rxjs"); var operators_1 = require("rxjs/operators"); var Interrupter = /** @class */ (function () { function Interrupter(provisioning) { var _this = this; this.provisioning = provisioning; this.observable = new rxjs_1.Subject(); this.provisioning.subscribe(function (state) { _this.observable.next(state); }); } Interrupter.prototype.toObservable = function (_a) { var _this = this; var disposeWhenUnsubscribe = (_a === void 0 ? { disposeWhenUnsubscribe: true, } : _a).disposeWhenUnsubscribe; return rxjs_1.Observable.create(function (subscriber) { var sub = _this.observable.subscribe(function (v) { return subscriber.next(v); }); return function () { sub.unsubscribe(); if (disposeWhenUnsubscribe) { _this.provisioning.dispose(); } }; }); }; Interrupter.prototype.send = function (type, payload) { if (payload === void 0) { payload = {}; } this.provisioning.getSubject().notify({ type: type, payload: payload }); }; Interrupter.prototype.subscribe = function (callback, runInitial) { if (runInitial === void 0) { runInitial = false; } return this.provisioning.subscribe(callback, runInitial); }; Interrupter.prototype.dispose = function () { this.provisioning.dispose(); }; Interrupter.prototype.wait = function (type) { return this.provisioning .getSubject() .observable.pipe(operators_1.filter(function (args) { return args.type === type; })) .toPromise(); }; return Interrupter; }()); exports.Interrupter = Interrupter;