source: trip-planner-front/node_modules/rxjs/internal/operators/delayWhen.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.8 KB
Line 
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
8 }
9 return function (d, b) {
10 extendStatics(d, b);
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13 };
14})();
15Object.defineProperty(exports, "__esModule", { value: true });
16var Subscriber_1 = require("../Subscriber");
17var Observable_1 = require("../Observable");
18var OuterSubscriber_1 = require("../OuterSubscriber");
19var subscribeToResult_1 = require("../util/subscribeToResult");
20function delayWhen(delayDurationSelector, subscriptionDelay) {
21 if (subscriptionDelay) {
22 return function (source) {
23 return new SubscriptionDelayObservable(source, subscriptionDelay)
24 .lift(new DelayWhenOperator(delayDurationSelector));
25 };
26 }
27 return function (source) { return source.lift(new DelayWhenOperator(delayDurationSelector)); };
28}
29exports.delayWhen = delayWhen;
30var DelayWhenOperator = (function () {
31 function DelayWhenOperator(delayDurationSelector) {
32 this.delayDurationSelector = delayDurationSelector;
33 }
34 DelayWhenOperator.prototype.call = function (subscriber, source) {
35 return source.subscribe(new DelayWhenSubscriber(subscriber, this.delayDurationSelector));
36 };
37 return DelayWhenOperator;
38}());
39var DelayWhenSubscriber = (function (_super) {
40 __extends(DelayWhenSubscriber, _super);
41 function DelayWhenSubscriber(destination, delayDurationSelector) {
42 var _this = _super.call(this, destination) || this;
43 _this.delayDurationSelector = delayDurationSelector;
44 _this.completed = false;
45 _this.delayNotifierSubscriptions = [];
46 _this.index = 0;
47 return _this;
48 }
49 DelayWhenSubscriber.prototype.notifyNext = function (outerValue, _innerValue, _outerIndex, _innerIndex, innerSub) {
50 this.destination.next(outerValue);
51 this.removeSubscription(innerSub);
52 this.tryComplete();
53 };
54 DelayWhenSubscriber.prototype.notifyError = function (error, innerSub) {
55 this._error(error);
56 };
57 DelayWhenSubscriber.prototype.notifyComplete = function (innerSub) {
58 var value = this.removeSubscription(innerSub);
59 if (value) {
60 this.destination.next(value);
61 }
62 this.tryComplete();
63 };
64 DelayWhenSubscriber.prototype._next = function (value) {
65 var index = this.index++;
66 try {
67 var delayNotifier = this.delayDurationSelector(value, index);
68 if (delayNotifier) {
69 this.tryDelay(delayNotifier, value);
70 }
71 }
72 catch (err) {
73 this.destination.error(err);
74 }
75 };
76 DelayWhenSubscriber.prototype._complete = function () {
77 this.completed = true;
78 this.tryComplete();
79 this.unsubscribe();
80 };
81 DelayWhenSubscriber.prototype.removeSubscription = function (subscription) {
82 subscription.unsubscribe();
83 var subscriptionIdx = this.delayNotifierSubscriptions.indexOf(subscription);
84 if (subscriptionIdx !== -1) {
85 this.delayNotifierSubscriptions.splice(subscriptionIdx, 1);
86 }
87 return subscription.outerValue;
88 };
89 DelayWhenSubscriber.prototype.tryDelay = function (delayNotifier, value) {
90 var notifierSubscription = subscribeToResult_1.subscribeToResult(this, delayNotifier, value);
91 if (notifierSubscription && !notifierSubscription.closed) {
92 var destination = this.destination;
93 destination.add(notifierSubscription);
94 this.delayNotifierSubscriptions.push(notifierSubscription);
95 }
96 };
97 DelayWhenSubscriber.prototype.tryComplete = function () {
98 if (this.completed && this.delayNotifierSubscriptions.length === 0) {
99 this.destination.complete();
100 }
101 };
102 return DelayWhenSubscriber;
103}(OuterSubscriber_1.OuterSubscriber));
104var SubscriptionDelayObservable = (function (_super) {
105 __extends(SubscriptionDelayObservable, _super);
106 function SubscriptionDelayObservable(source, subscriptionDelay) {
107 var _this = _super.call(this) || this;
108 _this.source = source;
109 _this.subscriptionDelay = subscriptionDelay;
110 return _this;
111 }
112 SubscriptionDelayObservable.prototype._subscribe = function (subscriber) {
113 this.subscriptionDelay.subscribe(new SubscriptionDelaySubscriber(subscriber, this.source));
114 };
115 return SubscriptionDelayObservable;
116}(Observable_1.Observable));
117var SubscriptionDelaySubscriber = (function (_super) {
118 __extends(SubscriptionDelaySubscriber, _super);
119 function SubscriptionDelaySubscriber(parent, source) {
120 var _this = _super.call(this) || this;
121 _this.parent = parent;
122 _this.source = source;
123 _this.sourceSubscribed = false;
124 return _this;
125 }
126 SubscriptionDelaySubscriber.prototype._next = function (unused) {
127 this.subscribeToSource();
128 };
129 SubscriptionDelaySubscriber.prototype._error = function (err) {
130 this.unsubscribe();
131 this.parent.error(err);
132 };
133 SubscriptionDelaySubscriber.prototype._complete = function () {
134 this.unsubscribe();
135 this.subscribeToSource();
136 };
137 SubscriptionDelaySubscriber.prototype.subscribeToSource = function () {
138 if (!this.sourceSubscribed) {
139 this.sourceSubscribed = true;
140 this.unsubscribe();
141 this.source.subscribe(this.parent);
142 }
143 };
144 return SubscriptionDelaySubscriber;
145}(Subscriber_1.Subscriber));
146//# sourceMappingURL=delayWhen.js.map
Note: See TracBrowser for help on using the repository browser.