1 import { Subscriber } from '../Subscriber';
2 export function bufferCount(bufferSize, startBufferEvery = null) {
3 return function bufferCountOperatorFunction(source) {
4 return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
7 class BufferCountOperator {
8 constructor(bufferSize, startBufferEvery) {
9 this.bufferSize = bufferSize;
10 this.startBufferEvery = startBufferEvery;
11 if (!startBufferEvery || bufferSize === startBufferEvery) {
12 this.subscriberClass = BufferCountSubscriber;
15 this.subscriberClass = BufferSkipCountSubscriber;
18 call(subscriber, source) {
19 return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
22 class BufferCountSubscriber extends Subscriber {
23 constructor(destination, bufferSize) {
25 this.bufferSize = bufferSize;
29 const buffer = this.buffer;
31 if (buffer.length == this.bufferSize) {
32 this.destination.next(buffer);
37 const buffer = this.buffer;
38 if (buffer.length > 0) {
39 this.destination.next(buffer);
44 class BufferSkipCountSubscriber extends Subscriber {
45 constructor(destination, bufferSize, startBufferEvery) {
47 this.bufferSize = bufferSize;
48 this.startBufferEvery = startBufferEvery;
53 const { bufferSize, startBufferEvery, buffers, count } = this;
55 if (count % startBufferEvery === 0) {
58 for (let i = buffers.length; i--;) {
59 const buffer = buffers[i];
61 if (buffer.length === bufferSize) {
63 this.destination.next(buffer);
68 const { buffers, destination } = this;
69 while (buffers.length > 0) {
70 let buffer = buffers.shift();
71 if (buffer.length > 0) {
72 destination.next(buffer);
78 //# sourceMappingURL=bufferCount.js.map