Skip to content

Commit 1548393

Browse files
cartantbenlesh
authored andcommitted
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
1 parent be952c0 commit 1548393

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spec/operators/debounce-spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ describe('Observable.prototype.debounce', () => {
4444
expectSubscriptions(e1.subscriptions).toBe(e1subs);
4545
});
4646

47+
it('should support a scalar selector observable', () => {
48+
49+
// If the selector returns a scalar observable, the debounce operator
50+
// should emit the value immediately.
51+
52+
const e1 = hot('--a--bc--d----|');
53+
const e1subs = '^ !';
54+
const expected = '--a--bc--d----|';
55+
56+
expectObservable(e1.debounce(() => Rx.Observable.of(0))).toBe(expected);
57+
expectSubscriptions(e1.subscriptions).toBe(e1subs);
58+
});
59+
4760
it('should complete when source does not emit', () => {
4861
const e1 = hot('-----|');
4962
const e1subs = '^ !';

src/internal/operators/debounce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class DebounceSubscriber<T, R> extends OuterSubscriber<T, R> {
105105
}
106106

107107
subscription = subscribeToResult(this, duration);
108-
if (!subscription.closed) {
108+
if (subscription && !subscription.closed) {
109109
this.add(this.durationSubscription = subscription);
110110
}
111111
}

0 commit comments

Comments
 (0)