diff --git a/src/operator/windowWhen.ts b/src/operator/windowWhen.ts index 5d681b604d..df70d01b91 100644 --- a/src/operator/windowWhen.ts +++ b/src/operator/windowWhen.ts @@ -16,16 +16,17 @@ class WindowOperator implements Operator { constructor(private closingSelector: () => Observable) { } - call(subscriber: Subscriber): Subscriber { + call(subscriber: Subscriber>): Subscriber { return new WindowSubscriber(subscriber, this.closingSelector); } } class WindowSubscriber extends Subscriber { - private window: Subject = new Subject(); + private window: Subject; private closingNotification: Subscription; - constructor(destination: Subscriber, private closingSelector: () => Observable) { + constructor(protected destination: Subscriber>, + private closingSelector: () => Observable) { super(destination); this.openWindow(); } @@ -70,16 +71,19 @@ class WindowSubscriber extends Subscriber { prevWindow.complete(); } - this.destination.next(this.window = new Subject()); + const window = this.window = new Subject(); + 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); } } }