2 var __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);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subject_1 = require("../Subject");
17 var OuterSubscriber_1 = require("../OuterSubscriber");
18 var subscribeToResult_1 = require("../util/subscribeToResult");
19 function repeatWhen(notifier) {
20 return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
22 exports.repeatWhen = repeatWhen;
23 var RepeatWhenOperator = (function () {
24 function RepeatWhenOperator(notifier) {
25 this.notifier = notifier;
27 RepeatWhenOperator.prototype.call = function (subscriber, source) {
28 return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
30 return RepeatWhenOperator;
32 var RepeatWhenSubscriber = (function (_super) {
33 __extends(RepeatWhenSubscriber, _super);
34 function RepeatWhenSubscriber(destination, notifier, source) {
35 var _this = _super.call(this, destination) || this;
36 _this.notifier = notifier;
37 _this.source = source;
38 _this.sourceIsBeingSubscribedTo = true;
41 RepeatWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
42 this.sourceIsBeingSubscribedTo = true;
43 this.source.subscribe(this);
45 RepeatWhenSubscriber.prototype.notifyComplete = function (innerSub) {
46 if (this.sourceIsBeingSubscribedTo === false) {
47 return _super.prototype.complete.call(this);
50 RepeatWhenSubscriber.prototype.complete = function () {
51 this.sourceIsBeingSubscribedTo = false;
52 if (!this.isStopped) {
54 this.subscribeToRetries();
56 if (!this.retriesSubscription || this.retriesSubscription.closed) {
57 return _super.prototype.complete.call(this);
59 this._unsubscribeAndRecycle();
60 this.notifications.next();
63 RepeatWhenSubscriber.prototype._unsubscribe = function () {
64 var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
66 notifications.unsubscribe();
67 this.notifications = null;
69 if (retriesSubscription) {
70 retriesSubscription.unsubscribe();
71 this.retriesSubscription = null;
75 RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
76 var _unsubscribe = this._unsubscribe;
77 this._unsubscribe = null;
78 _super.prototype._unsubscribeAndRecycle.call(this);
79 this._unsubscribe = _unsubscribe;
82 RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
83 this.notifications = new Subject_1.Subject();
86 var notifier = this.notifier;
87 retries = notifier(this.notifications);
90 return _super.prototype.complete.call(this);
92 this.retries = retries;
93 this.retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries);
95 return RepeatWhenSubscriber;
96 }(OuterSubscriber_1.OuterSubscriber));
97 //# sourceMappingURL=repeatWhen.js.map