Skip to content

Commit

Permalink
fix(windowCount): fix windowCount to dispose window Subjects
Browse files Browse the repository at this point in the history
Fix windowCount() operator to dispose window Subjects when the destination Subscriber is
unsubscribed.
  • Loading branch information
staltz authored and kwonoj committed Dec 9, 2015
1 parent 07e8c53 commit f29ee29
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/operator/windowCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ class WindowCountSubscriber<T> extends Subscriber<T> {
private windows: Subject<T>[] = [ new Subject<T>() ];
private count: number = 0;

constructor(destination: Subscriber<Observable<T>>,
constructor(protected destination: Subscriber<Observable<T>>,
private windowSize: number,
private startWindowEvery: number) {
super(destination);
destination.next(this.windows[0]);
const firstWindow = this.windows[0];
destination.add(firstWindow);
destination.next(firstWindow);
}

_next(value: T) {
const startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
const destination = this.destination;
const windowSize = this.windowSize;
const windows = this.windows;
const len = windows.length;
Expand All @@ -44,9 +47,10 @@ class WindowCountSubscriber<T> extends Subscriber<T> {
windows.shift().complete();
}
if (++this.count % startWindowEvery === 0) {
let window = new Subject<T>();
const window = new Subject<T>();
windows.push(window);
this.destination.next(window);
destination.add(window);
destination.next(window);
}
}

Expand Down

0 comments on commit f29ee29

Please sign in to comment.