1 import { Subscriber } from '../Subscriber';
2 import { Subject } from '../Subject';
3 export function windowCount(windowSize, startWindowEvery = 0) {
4 return function windowCountOperatorFunction(source) {
5 return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
8 class WindowCountOperator {
9 constructor(windowSize, startWindowEvery) {
10 this.windowSize = windowSize;
11 this.startWindowEvery = startWindowEvery;
13 call(subscriber, source) {
14 return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
17 class WindowCountSubscriber extends Subscriber {
18 constructor(destination, windowSize, startWindowEvery) {
20 this.destination = destination;
21 this.windowSize = windowSize;
22 this.startWindowEvery = startWindowEvery;
23 this.windows = [new Subject()];
25 destination.next(this.windows[0]);
28 const startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
29 const destination = this.destination;
30 const windowSize = this.windowSize;
31 const windows = this.windows;
32 const len = windows.length;
33 for (let i = 0; i < len && !this.closed; i++) {
34 windows[i].next(value);
36 const c = this.count - windowSize + 1;
37 if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
38 windows.shift().complete();
40 if (++this.count % startWindowEvery === 0 && !this.closed) {
41 const window = new Subject();
43 destination.next(window);
47 const windows = this.windows;
49 while (windows.length > 0 && !this.closed) {
50 windows.shift().error(err);
53 this.destination.error(err);
56 const windows = this.windows;
58 while (windows.length > 0 && !this.closed) {
59 windows.shift().complete();
62 this.destination.complete();
69 //# sourceMappingURL=windowCount.js.map