From 336847b180eabec1c99d4ec05db6d4c4a9748c2e Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Fri, 19 Jan 2018 16:48:10 +1000 Subject: [PATCH 1/3] test(debounce): add failing scalar selector test --- spec/operators/debounce-spec.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/operators/debounce-spec.ts b/spec/operators/debounce-spec.ts index dcff8f230d..335d8921cc 100644 --- a/spec/operators/debounce-spec.ts +++ b/spec/operators/debounce-spec.ts @@ -44,6 +44,15 @@ describe('Observable.prototype.debounce', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + it('should debounce by scalar selector observable', () => { + const e1 = hot('--a--bc--d----|'); + const e1subs = '^ !'; + const expected = '--a--bc--d----|'; + + expectObservable(e1.debounce(() => Rx.Observable.of(0))).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); + it('should complete when source does not emit', () => { const e1 = hot('-----|'); const e1subs = '^ !'; From 5a633f94f343bcddd31d4888362dcefe4b5c3573 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Fri, 19 Jan 2018 16:56:26 +1000 Subject: [PATCH 2/3] fix(debounce): support scalar selectors Closes #3232 --- src/internal/operators/debounce.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/operators/debounce.ts b/src/internal/operators/debounce.ts index 127948784d..8477535c0b 100644 --- a/src/internal/operators/debounce.ts +++ b/src/internal/operators/debounce.ts @@ -105,7 +105,7 @@ class DebounceSubscriber extends OuterSubscriber { } subscription = subscribeToResult(this, duration); - if (!subscription.closed) { + if (subscription && !subscription.closed) { this.add(this.durationSubscription = subscription); } } From 54e6bef9d9ed4ddb0e9fb0ecf635a086f5b1e797 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Fri, 19 Jan 2018 17:09:24 +1000 Subject: [PATCH 3/3] test(debounce): rename and comment test --- spec/operators/debounce-spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/operators/debounce-spec.ts b/spec/operators/debounce-spec.ts index 335d8921cc..8616e786b1 100644 --- a/spec/operators/debounce-spec.ts +++ b/spec/operators/debounce-spec.ts @@ -44,7 +44,11 @@ describe('Observable.prototype.debounce', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); - it('should debounce by scalar selector observable', () => { + it('should support a scalar selector observable', () => { + + // If the selector returns a scalar observable, the debounce operator + // should emit the value immediately. + const e1 = hot('--a--bc--d----|'); const e1subs = '^ !'; const expected = '--a--bc--d----|';