UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

60 lines 2.52 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; define(["require", "exports", '../Observable', '../util/subscribeToResult', '../OuterSubscriber'], function (require, exports, Observable_1, subscribeToResult_1, OuterSubscriber_1) { "use strict"; /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} * @hide true */ var IfObservable = (function (_super) { __extends(IfObservable, _super); function IfObservable(condition, thenSource, elseSource) { _super.call(this); this.condition = condition; this.thenSource = thenSource; this.elseSource = elseSource; } IfObservable.create = function (condition, thenSource, elseSource) { return new IfObservable(condition, thenSource, elseSource); }; IfObservable.prototype._subscribe = function (subscriber) { var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource; return new IfSubscriber(subscriber, condition, thenSource, elseSource); }; return IfObservable; }(Observable_1.Observable)); exports.IfObservable = IfObservable; var IfSubscriber = (function (_super) { __extends(IfSubscriber, _super); function IfSubscriber(destination, condition, thenSource, elseSource) { _super.call(this, destination); this.condition = condition; this.thenSource = thenSource; this.elseSource = elseSource; this.tryIf(); } IfSubscriber.prototype.tryIf = function () { var _a = this, condition = _a.condition, thenSource = _a.thenSource, elseSource = _a.elseSource; var result; try { result = condition(); var source = result ? thenSource : elseSource; if (source) { this.add(subscribeToResult_1.subscribeToResult(this, source)); } else { this._complete(); } } catch (err) { this._error(err); } }; return IfSubscriber; }(OuterSubscriber_1.OuterSubscriber)); }); //# sourceMappingURL=IfObservable.js.map