UNPKG

@rxx/testing

Version:
49 lines (48 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rxjs_1 = require("rxjs"); var Interrupter = (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); }); this.publisher = this.provisioning.getSubject(); } 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.publisher.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) { var _this = this; return new Promise(function (resolve) { _this.provisioning.subscribe(function (payload) { return resolve(payload); }); }); }; return Interrupter; }()); exports.Interrupter = Interrupter;