Skip to content

Commit

Permalink
fix(windowWhen): fix windowWhen to dispose window Subjects
Browse files Browse the repository at this point in the history
Fix windowWhen operator to dispose window Subjects when the destination Subscriber is unsubscribed.
  • Loading branch information
staltz authored and kwonoj committed Dec 9, 2015
1 parent 4891957 commit 91c1941
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/operator/windowWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ class WindowOperator<T, R> implements Operator<T, R> {
constructor(private closingSelector: () => Observable<any>) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
call(subscriber: Subscriber<Observable<T>>): Subscriber<T> {
return new WindowSubscriber(subscriber, this.closingSelector);
}
}

class WindowSubscriber<T> extends Subscriber<T> {
private window: Subject<T> = new Subject<T>();
private window: Subject<T>;
private closingNotification: Subscription<any>;

constructor(destination: Subscriber<T>, private closingSelector: () => Observable<any>) {
constructor(protected destination: Subscriber<Observable<T>>,
private closingSelector: () => Observable<any>) {
super(destination);
this.openWindow();
}
Expand Down Expand Up @@ -70,16 +71,19 @@ class WindowSubscriber<T> extends Subscriber<T> {
prevWindow.complete();
}

this.destination.next(this.window = new Subject<T>());
const window = this.window = new Subject<T>();
this.destination.next(window);

let closingNotifier = tryCatch(this.closingSelector)();
const closingNotifier = tryCatch(this.closingSelector)();
if (closingNotifier === errorObject) {
const err = closingNotifier.e;
this.destination.error(err);
this.window.error(err);
} else {
let closingNotification = this.closingNotification = new Subscription();
this.add(closingNotification.add(closingNotifier._subscribe(new WindowClosingNotifierSubscriber(this))));
const closingNotification = this.closingNotification = new Subscription();
closingNotification.add(closingNotifier._subscribe(new WindowClosingNotifierSubscriber(this)));
this.add(closingNotification);
this.add(window);
}
}
}
Expand Down

0 comments on commit 91c1941

Please sign in to comment.