Skip to content

Commit

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

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

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

constructor(destination: Subscriber<T>, private closingNotifier: Observable<any>) {
constructor(protected destination: Subscriber<Observable<T>>,
private closingNotifier: Observable<any>) {
super(destination);
this.add(closingNotifier._subscribe(new WindowClosingNotifierSubscriber(this)));
this.openWindow();
Expand All @@ -45,7 +46,10 @@ class WindowSubscriber<T> extends Subscriber<T> {
if (prevWindow) {
prevWindow.complete();
}
this.destination.next(this.window = new Subject<T>());
const destination = this.destination;
const newWindow = this.window = new Subject<T>();
destination.add(newWindow);
destination.next(newWindow);
}
}

Expand Down

0 comments on commit 5168f73

Please sign in to comment.