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 innerSubscribe_1 = require("../innerSubscribe");
18 function repeatWhen(notifier) {
19 return function (source) { return source.lift(new RepeatWhenOperator(notifier)); };
21 exports.repeatWhen = repeatWhen;
22 var RepeatWhenOperator = (function () {
23 function RepeatWhenOperator(notifier) {
24 this.notifier = notifier;
26 RepeatWhenOperator.prototype.call = function (subscriber, source) {
27 return source.subscribe(new RepeatWhenSubscriber(subscriber, this.notifier, source));
29 return RepeatWhenOperator;
31 var RepeatWhenSubscriber = (function (_super) {
32 __extends(RepeatWhenSubscriber, _super);
33 function RepeatWhenSubscriber(destination, notifier, source) {
34 var _this = _super.call(this, destination) || this;
35 _this.notifier = notifier;
36 _this.source = source;
37 _this.sourceIsBeingSubscribedTo = true;
40 RepeatWhenSubscriber.prototype.notifyNext = function () {
41 this.sourceIsBeingSubscribedTo = true;
42 this.source.subscribe(this);
44 RepeatWhenSubscriber.prototype.notifyComplete = function () {
45 if (this.sourceIsBeingSubscribedTo === false) {
46 return _super.prototype.complete.call(this);
49 RepeatWhenSubscriber.prototype.complete = function () {
50 this.sourceIsBeingSubscribedTo = false;
51 if (!this.isStopped) {
53 this.subscribeToRetries();
55 if (!this.retriesSubscription || this.retriesSubscription.closed) {
56 return _super.prototype.complete.call(this);
58 this._unsubscribeAndRecycle();
59 this.notifications.next(undefined);
62 RepeatWhenSubscriber.prototype._unsubscribe = function () {
63 var _a = this, notifications = _a.notifications, retriesSubscription = _a.retriesSubscription;
65 notifications.unsubscribe();
66 this.notifications = undefined;
68 if (retriesSubscription) {
69 retriesSubscription.unsubscribe();
70 this.retriesSubscription = undefined;
72 this.retries = undefined;
74 RepeatWhenSubscriber.prototype._unsubscribeAndRecycle = function () {
75 var _unsubscribe = this._unsubscribe;
76 this._unsubscribe = null;
77 _super.prototype._unsubscribeAndRecycle.call(this);
78 this._unsubscribe = _unsubscribe;
81 RepeatWhenSubscriber.prototype.subscribeToRetries = function () {
82 this.notifications = new Subject_1.Subject();
85 var notifier = this.notifier;
86 retries = notifier(this.notifications);
89 return _super.prototype.complete.call(this);
91 this.retries = retries;
92 this.retriesSubscription = innerSubscribe_1.innerSubscribe(retries, new innerSubscribe_1.SimpleInnerSubscriber(this));
94 return RepeatWhenSubscriber;
95 }(innerSubscribe_1.SimpleOuterSubscriber));
96 //# sourceMappingURL=repeatWhen.js.map