Skip to content

Commit 2269618

Browse files
trxcllntbenlesh
authored andcommitted
fix(groupBy): Fix groupBy to dispose of outer subscription. (#2201)
1 parent 45b842c commit 2269618

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

spec/operators/groupBy-spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,34 @@ describe('Observable.prototype.groupBy', () => {
340340
expectSubscriptions(e1.subscriptions).toBe(e1subs);
341341
});
342342

343+
it('should unsubscribe from the source when the outer and inner subscriptions are disposed', () => {
344+
const values = {
345+
a: ' foo',
346+
b: ' FoO ',
347+
c: 'baR ',
348+
d: 'foO ',
349+
e: ' Baz ',
350+
f: ' qux ',
351+
g: ' bar',
352+
h: ' BAR ',
353+
i: 'FOO ',
354+
j: 'baz ',
355+
k: ' bAZ ',
356+
l: ' fOo '
357+
};
358+
const e1 = hot('-1--2--^-a-b-c-d-e-f-g-h-i-j-k-l-|', values);
359+
const e1subs = '^ !';
360+
const expected = '--(a|)';
361+
362+
const source = e1
363+
.groupBy((val: string) => val.toLowerCase().trim())
364+
.take(1)
365+
.mergeMap((group: any) => group.take(1));
366+
367+
expectObservable(source).toBe(expected, values);
368+
expectSubscriptions(e1.subscriptions).toBe(e1subs);
369+
});
370+
343371
it('should not break unsubscription chain when unsubscribed explicitly', () => {
344372
const values = {
345373
a: ' foo',

src/operator/groupBy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class GroupBySubscriber<T, K, R> extends Subscriber<T> implements RefCountSubscr
163163
}
164164

165165
unsubscribe() {
166-
if (!this.closed && !this.attemptedToUnsubscribe) {
166+
if (!this.closed) {
167167
this.attemptedToUnsubscribe = true;
168168
if (this.count === 0) {
169169
super.unsubscribe();

0 commit comments

Comments
 (0)