From d9a7328e78a9ca69fa86a8197924b1e7a4956b6a Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Sat, 5 Dec 2015 13:13:05 +0200 Subject: [PATCH] fix(repeat): preserve Subscriber chain in repeat() Fix repeat() operator to add its own Subscriber to the destination Subscriber, in order to avoid breaking unsubscription chains. For issue #875. --- src/operator/repeat.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/operator/repeat.ts b/src/operator/repeat.ts index 99eb232b9e..d2296e964b 100644 --- a/src/operator/repeat.ts +++ b/src/operator/repeat.ts @@ -28,7 +28,8 @@ class FirstRepeatSubscriber extends Subscriber { constructor(public destination: Subscriber, private count: number, private source: Observable) { - super(null); + super(); + destination.add(this); this.lastSubscription = this; } @@ -56,12 +57,15 @@ class FirstRepeatSubscriber extends Subscriber { } resubscribe(count: number): void { - this.lastSubscription.unsubscribe(); + const { destination, lastSubscription } = this; + destination.remove(lastSubscription); + lastSubscription.unsubscribe(); if (count - 1 === 0) { - this.destination.complete(); + destination.complete(); } else { const nextSubscriber = new MoreRepeatSubscriber(this, count - 1); this.lastSubscription = this.source.subscribe(nextSubscriber); + destination.add(this.lastSubscription); } } } @@ -69,7 +73,7 @@ class FirstRepeatSubscriber extends Subscriber { class MoreRepeatSubscriber extends Subscriber { constructor(private parent: FirstRepeatSubscriber, private count: number) { - super(null); + super(); } _next(value: T): void {