Skip to content

Commit

Permalink
fix(windowToggle): handle closingSelector completes immediately
Browse files Browse the repository at this point in the history
closes #1487
  • Loading branch information
kwonoj committed Mar 22, 2016
1 parent 0ac7e1e commit c755587
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 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);
});
});
16 changes: 13 additions & 3 deletions src/operator/windowToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,16 @@ class WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {
const context = { window, subscription };
this.contexts.push(context);
const innerSubscription = subscribeToResult(this, closingNotifier, context);
(<any> innerSubscription).context = context;
subscription.add(innerSubscription);

if (innerSubscription.isUnsubscribed) {
this.closeWindow(this.contexts.length - 1);
} else {
(<any> innerSubscription).context = context;
subscription.add(innerSubscription);
}

this.destination.next(window);

}
} else {
this.closeWindow(this.contexts.indexOf(outerValue));
Expand All @@ -151,7 +157,11 @@ class WindowToggleSubscriber<T, O> extends OuterSubscriber<T, any> {
}
}

closeWindow(index: number) {
private closeWindow(index: number): void {
if (index === -1) {
return;
}

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

0 comments on commit c755587

Please sign in to comment.