Skip to content

Commit

Permalink
fix(groupBy): Fix groupBy to dispose of outer subscription. (#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt authored and benlesh committed Dec 23, 2016
1 parent 45b842c commit 2269618
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 2269618

Please sign in to comment.