123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /** PURE_IMPORTS_START tslib,_Subscriber,_Observable,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
- import * as tslib_1 from "tslib";
- import { Subscriber } from '../Subscriber';
- import { Observable } from '../Observable';
- import { OuterSubscriber } from '../OuterSubscriber';
- import { subscribeToResult } from '../util/subscribeToResult';
- export function delayWhen(delayDurationSelector, subscriptionDelay) {
- if (subscriptionDelay) {
- return function (source) {
- return new SubscriptionDelayObservable(source, subscriptionDelay)
- .lift(new DelayWhenOperator(delayDurationSelector));
- };
- }
- return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
- }
- var DelayWhenOperator = /*@__PURE__*/ (function () {
- function DelayWhenOperator(delayDurationSelector) {
- this.delayDurationSelector = delayDurationSelector;
- }
- DelayWhenOperator.prototype.call = function (subscriber, source) {
- return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
- };
- return DelayWhenOperator;
- }());
- var DelayWhenSubscriber = /*@__PURE__*/ (function (_super) {
- tslib_1.__extends(DelayWhenSubscriber, _super);
- function DelayWhenSubscriber(destination, delayDurationSelector) {
- var _this = _super.call(this, destination) || this;
- _this.delayDurationSelector = delayDurationSelector;
- _this.completed = false;
- _this.delayNotifierSubscriptions = [];
- _this.index = 0;
- return _this;
- }
- DelayWhenSubscriber.prototype.notifyNext = function (outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
- this.destination.next(outerValue);
- this.removeSubscription(innerSub);
- this.tryComplete();
- };
- DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
- this._error(error);
- };
- DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
- var value = this.removeSubscription(innerSub);
- if (value) {
- this.destination.next(value);
- }
- this.tryComplete();
- };
- DelayWhenSubscriber.prototype._next = function (value) {
- var index = this.index++;
- try {
- var delayNotifier = this.delayDurationSelector(value, index);
- if (delayNotifier) {
- this.tryDelay(delayNotifier, value);
- }
- }
- catch (err) {
- this.destination.error(err);
- }
- };
- DelayWhenSubscriber.prototype._complete = function () {
- this.completed = true;
- this.tryComplete();
- this.unsubscribe();
- };
- DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
- subscription.unsubscribe();
- var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
- if (subscriptionIdx !== -1) {
- this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
- }
- return subscription.outerValue;
- };
- DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
- var notifierSubscription = subscribeToResult(this, delayNotifier, value);
- if (notifierSubscription && !notifierSubscription.closed) {
- var destination = this.destination;
- destination.add(notifierSubscription);
- this.delayNotifierSubscriptions.push(notifierSubscription);
- }
- };
- DelayWhenSubscriber.prototype.tryComplete = function () {
- if (this.completed && this.delayNotifierSubscriptions.length === 0) {
- this.destination.complete();
- }
- };
- return DelayWhenSubscriber;
- }(OuterSubscriber));
- var SubscriptionDelayObservable = /*@__PURE__*/ (function (_super) {
- tslib_1.__extends(SubscriptionDelayObservable, _super);
- function SubscriptionDelayObservable(source, subscriptionDelay) {
- var _this = _super.call(this) || this;
- _this.source = source;
- _this.subscriptionDelay = subscriptionDelay;
- return _this;
- }
- SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
- this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
- };
- return SubscriptionDelayObservable;
- }(Observable));
- var SubscriptionDelaySubscriber = /*@__PURE__*/ (function (_super) {
- tslib_1.__extends(SubscriptionDelaySubscriber, _super);
- function SubscriptionDelaySubscriber(parent, source) {
- var _this = _super.call(this) || this;
- _this.parent = parent;
- _this.source = source;
- _this.sourceSubscribed = false;
- return _this;
- }
- SubscriptionDelaySubscriber.prototype._next = function (unused) {
- this.subscribeToSource();
- };
- SubscriptionDelaySubscriber.prototype._error = function (err) {
- this.unsubscribe();
- this.parent.error(err);
- };
- SubscriptionDelaySubscriber.prototype._complete = function () {
- this.unsubscribe();
- this.subscribeToSource();
- };
- SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
- if (!this.sourceSubscribed) {
- this.sourceSubscribed = true;
- this.unsubscribe();
- this.source.subscribe(this.parent);
- }
- };
- return SubscriptionDelaySubscriber;
- }(Subscriber));
- //# sourceMappingURL=delayWhen.js.map
|