From 154839321f06587982a41a0cd944a111715b2cf6 Mon Sep 17 00:00:00 2001 From: Nicholas Jamieson Date: Sat, 20 Jan 2018 07:28:50 +1000 Subject: [PATCH] fix(debounce): support scalar selectors (#3236) * test(debounce): add failing scalar selector test * fix(debounce): support scalar selectors Closes #3232 * test(debounce): rename and comment test --- spec/operators/debounce-spec.ts | 13 +++++++++++++ src/internal/operators/debounce.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/operators/debounce-spec.ts b/spec/operators/debounce-spec.ts index dcff8f230d..8616e786b1 100644 --- a/spec/operators/debounce-spec.ts +++ b/spec/operators/debounce-spec.ts @@ -44,6 +44,19 @@ describe('Observable.prototype.debounce', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + 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----|'; + + 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 = '^ !'; 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); } }