Skip to content

Commit 15ff3f7

Browse files
staltzkwonoj
authored andcommitted
fix(windowToggle): fix windowToggle to dispose window Subjects
Fix windowToggle() operator to dispose window Subjects when the destination Subscriber is unsubscribed.
1 parent c346230 commit 15ff3f7

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/operator/windowToggle.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WindowToggleOperator<T, R, O> implements Operator<T, R> {
1818
private closingSelector: (openValue: O) => Observable<any>) {
1919
}
2020

21-
call(subscriber: Subscriber<T>): Subscriber<T> {
21+
call(subscriber: Subscriber<Observable<T>>): Subscriber<T> {
2222
return new WindowToggleSubscriber<T, O>(
2323
subscriber, this.openings, this.closingSelector
2424
);
@@ -33,7 +33,7 @@ interface WindowContext<T> {
3333
class WindowToggleSubscriber<T, O> extends Subscriber<T> {
3434
private contexts: Array<WindowContext<T>> = [];
3535

36-
constructor(destination: Subscriber<T>,
36+
constructor(protected destination: Subscriber<Observable<T>>,
3737
private openings: Observable<O>,
3838
private closingSelector: (openValue: O) => Observable<any>) {
3939
super(destination);
@@ -72,24 +72,29 @@ class WindowToggleSubscriber<T, O> extends Subscriber<T> {
7272
if (closingNotifier === errorObject) {
7373
this.error(closingNotifier.e);
7474
} else {
75-
let context = {
76-
window: new Subject<T>(),
77-
subscription: new Subscription()
78-
};
75+
const destination = this.destination;
76+
const window = new Subject<T>();
77+
const subscription = new Subscription();
78+
const context = { window, subscription };
7979
this.contexts.push(context);
80-
this.destination.next(context.window);
8180
const subscriber = new WindowClosingNotifierSubscriber<T, O>(this, context);
82-
const subscription = closingNotifier._subscribe(subscriber);
83-
this.add(context.subscription.add(subscription));
81+
const closingSubscription = closingNotifier._subscribe(subscriber);
82+
subscription.add(closingSubscription);
83+
destination.add(subscription);
84+
destination.add(window);
85+
destination.next(window);
8486
}
8587
}
8688

8789
closeWindow(context: WindowContext<T>) {
8890
const { window, subscription } = context;
8991
const contexts = this.contexts;
92+
const destination = this.destination;
93+
9094
contexts.splice(contexts.indexOf(context), 1);
9195
window.complete();
92-
this.remove(subscription);
96+
destination.remove(subscription);
97+
destination.remove(window);
9398
subscription.unsubscribe();
9499
}
95100
}

0 commit comments

Comments
 (0)