Skip to content

Commit

Permalink
fix(groupBy): Fix groupBy to dispose of outer subscription.
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Dec 20, 2016
1 parent dc06e01 commit 6ea5b17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions spec/operators/groupBy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,34 @@ describe('Observable.prototype.groupBy', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should unsubscribe from the source when the outer and inner subscriptions are disposed', () => {
const values = {
a: ' foo',
b: ' FoO ',
c: 'baR ',
d: 'foO ',
e: ' Baz ',
f: ' qux ',
g: ' bar',
h: ' BAR ',
i: 'FOO ',
j: 'baz ',
k: ' bAZ ',
l: ' fOo '
};
const e1 = hot('-1--2--^-a-b-c-d-e-f-g-h-i-j-k-l-|', values);
const e1subs = '^ !';
const expected = '--(a|)';

const source = e1
.groupBy((val: string) => val.toLowerCase().trim())
.take(1)
.mergeMap((group: any) => group.take(1));

expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should not break unsubscription chain when unsubscribed explicitly', () => {
const values = {
a: ' foo',
Expand Down
2 changes: 1 addition & 1 deletion src/operator/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class GroupBySubscriber<T, K, R> extends Subscriber<T> implements RefCountSubscr
}

unsubscribe() {
if (!this.closed && !this.attemptedToUnsubscribe) {
if (!this.closed) {
this.attemptedToUnsubscribe = true;
if (this.count === 0) {
super.unsubscribe();
Expand Down

0 comments on commit 6ea5b17

Please sign in to comment.