From 5ee11e04bfdb28a22d3abd836c59033fca5f5514 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 16 Dec 2015 00:21:16 -0800 Subject: [PATCH] fix(debounceTime): align value emit behavior as same as RxJS4 due to current null check, debounceTime does not allow value to be undefined. This change updates behavior to align behavior as same as RxJS4 does. closes #1081 --- src/operator/debounceTime.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/operator/debounceTime.ts b/src/operator/debounceTime.ts index 529617b758..42f5d51273 100644 --- a/src/operator/debounceTime.ts +++ b/src/operator/debounceTime.ts @@ -20,7 +20,8 @@ class DebounceTimeOperator implements Operator { class DebounceTimeSubscriber extends Subscriber { private debouncedSubscription: Subscription = null; - private lastValue: any = null; + private lastValue: T = null; + private hasValue: boolean = false; constructor(destination: Subscriber, private dueTime: number, @@ -31,6 +32,7 @@ class DebounceTimeSubscriber extends Subscriber { _next(value: T) { this.clearDebounce(); this.lastValue = value; + this.hasValue = true; this.add(this.debouncedSubscription = this.scheduler.schedule(dispatchNext, this.dueTime, this)); } @@ -41,9 +43,11 @@ class DebounceTimeSubscriber extends Subscriber { debouncedNext(): void { this.clearDebounce(); - if (this.lastValue != null) { + + if (this.hasValue) { this.destination.next(this.lastValue); this.lastValue = null; + this.hasValue = false; } }