From dea7847c43061ccffc19d5fdd150240c76c9d50b Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 12 Nov 2015 15:03:43 +0200 Subject: [PATCH] fix(debounce): Fix debounce to unsubscribe duration Observables Fix debounce operator to unsubscribe the ongoing duration Observable if the outer subscriber gets a new 'next' value. Also fix the clearDebounce() method which was doing a null check, and is now doing a truthyness check, to catch also undefined cases. --- src/operators/debounce.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/operators/debounce.ts b/src/operators/debounce.ts index 6d15c009c0..9da5f5bb11 100644 --- a/src/operators/debounce.ts +++ b/src/operators/debounce.ts @@ -47,6 +47,7 @@ class DebounceSubscriber extends Subscriber { } this.lastValue = value; + this.clearDebounce(); this.add(this.debouncedSubscription = debounce._subscribe(new DurationSelectorSubscriber(this, currentIndex))); } } @@ -67,7 +68,8 @@ class DebounceSubscriber extends Subscriber { private clearDebounce(): void { const debouncedSubscription = this.debouncedSubscription; - if (debouncedSubscription !== null) { + if (debouncedSubscription) { + debouncedSubscription.unsubscribe(); this.remove(debouncedSubscription); this.debouncedSubscription = null; }