Skip to content

Commit f29ee29

Browse files
staltzkwonoj
authored andcommitted
fix(windowCount): fix windowCount to dispose window Subjects
Fix windowCount() operator to dispose window Subjects when the destination Subscriber is unsubscribed.
1 parent 07e8c53 commit f29ee29

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/operator/windowCount.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ class WindowCountSubscriber<T> extends Subscriber<T> {
2323
private windows: Subject<T>[] = [ new Subject<T>() ];
2424
private count: number = 0;
2525

26-
constructor(destination: Subscriber<Observable<T>>,
26+
constructor(protected destination: Subscriber<Observable<T>>,
2727
private windowSize: number,
2828
private startWindowEvery: number) {
2929
super(destination);
30-
destination.next(this.windows[0]);
30+
const firstWindow = this.windows[0];
31+
destination.add(firstWindow);
32+
destination.next(firstWindow);
3133
}
3234

3335
_next(value: T) {
3436
const startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
37+
const destination = this.destination;
3538
const windowSize = this.windowSize;
3639
const windows = this.windows;
3740
const len = windows.length;
@@ -44,9 +47,10 @@ class WindowCountSubscriber<T> extends Subscriber<T> {
4447
windows.shift().complete();
4548
}
4649
if (++this.count % startWindowEvery === 0) {
47-
let window = new Subject<T>();
50+
const window = new Subject<T>();
4851
windows.push(window);
49-
this.destination.next(window);
52+
destination.add(window);
53+
destination.next(window);
5054
}
5155
}
5256

0 commit comments

Comments
 (0)