From 3558a4f9477009b4cce7a64b848a0b0459390402 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 29 Oct 2015 11:35:12 +0200 Subject: [PATCH] refactor(skipUntil): call super(destination) constructor Change SkipUntilSubscriber to give the destination subscriber to the constructor in Subscriber. Adapt SkipUntilSubscriber to handle unsubscription-on-complete correctly, by overriding unsubscribe(). Addresses #577. --- src/Subscriber.ts | 18 +++++++++--------- src/operators/skipUntil.ts | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 6fec2a33568..e96bcc1c932 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -9,10 +9,10 @@ import Subscription from './Subscription'; export default class Subscriber extends Subscription implements Observer { protected destination: Observer; - private _subscription: Subscription; + protected _subscription: Subscription; + + protected _isUnsubscribed: boolean = false; - private _isUnsubscribed: boolean = false; - static create(next ?: (x?:any) => void, error ?: (e?:any) => void, complete?: () => void): Subscriber { @@ -22,15 +22,15 @@ export default class Subscriber extends Subscription implements Observer extends Subscription implements Observer) { super(); this.destination = destination; - + if (!destination) { return; } @@ -90,9 +90,9 @@ export default class Subscriber extends Subscription implements Observer implements Operator { class SkipUntilSubscriber extends Subscriber { private notificationSubscriber: NotificationSubscriber = null; - constructor(public destination: Subscriber, + constructor(destination: Subscriber, private notifier: Observable) { - super(null); + super(destination); this.notificationSubscriber = new NotificationSubscriber(this); this.add(this.notifier.subscribe(this.notificationSubscriber)); } @@ -42,6 +42,17 @@ class SkipUntilSubscriber extends Subscriber { } this.notificationSubscriber.unsubscribe(); } + + unsubscribe() { + if (this._isUnsubscribed) { + return; + } else if (this._subscription) { + this._subscription.unsubscribe(); + this._isUnsubscribed = true; + } else { + super.unsubscribe(); + } + } } class NotificationSubscriber extends Subscriber {