Skip to content

Commit dea7847

Browse files
staltzkwonoj
authored andcommitted
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.
1 parent f392a27 commit dea7847

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/operators/debounce.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DebounceSubscriber<T> extends Subscriber<T> {
4747
}
4848

4949
this.lastValue = value;
50+
this.clearDebounce();
5051
this.add(this.debouncedSubscription = debounce._subscribe(new DurationSelectorSubscriber(this, currentIndex)));
5152
}
5253
}
@@ -67,7 +68,8 @@ class DebounceSubscriber<T> extends Subscriber<T> {
6768
private clearDebounce(): void {
6869
const debouncedSubscription = this.debouncedSubscription;
6970

70-
if (debouncedSubscription !== null) {
71+
if (debouncedSubscription) {
72+
debouncedSubscription.unsubscribe();
7173
this.remove(debouncedSubscription);
7274
this.debouncedSubscription = null;
7375
}

0 commit comments

Comments
 (0)