UNPKG

@reactivex/rxjs

Version:

Reactive Extensions for modern JavaScript

54 lines 1.94 kB
import { Observable } from '../Observable'; import { subscribeToResult } from '../util/subscribeToResult'; import { OuterSubscriber } from '../OuterSubscriber'; /** * We need this JSDoc comment for affecting ESDoc. * @extends {Ignored} * @hide true */ export 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)); 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(this, source)); } else { this._complete(); } } catch (err) { this._error(err); } }; return IfSubscriber; }(OuterSubscriber)); //# sourceMappingURL=IfObservable.js.map