Skip to content

Commit

Permalink
fix(windowToggle): handle closingSelector completes immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Mar 18, 2016
1 parent 1c4f9f5 commit 13c3f0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/operators/windowToggle-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,22 @@ describe('Observable.prototype.windowToggle', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});

it ('should handle empty closing observable', () => {
const e1 = hot('--a--^---b---c---d---e---f---g---h------|');
const e1subs = '^ !';
const e2 = cold( '---o---------------o-----------| ');
const e2subs = '^ ! ';
const e3 = Observable.empty();
const expected = '---x---------------y---------------|';
const x = cold( '|');
const y = cold( '|');
const values = { x: x, y: y };

const result = e1.windowToggle(e2, () => e3);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
});
8 changes: 8 additions & 0 deletions src/operator/windowToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {
subscription.add(innerSubscription);

this.destination.next(window);

if (innerSubscription.isUnsubscribed) {
this.closeWindow(this.contexts.length - 1);
}
}
} else {
this.closeWindow(this.contexts.indexOf(outerValue));
Expand All @@ -152,6 +156,10 @@ class WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {
}

closeWindow(index: number) {
if (index < 0) {
return;
}

const { contexts } = this;
const context = contexts[index];
const { window, subscription } = context;
Expand Down

0 comments on commit 13c3f0e

Please sign in to comment.