You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
2.4 KiB
1 lines
2.4 KiB
{"ast":null,"code":"import { Subscriber } from '../Subscriber';\nexport function bufferCount(bufferSize, startBufferEvery = null) {\n return function bufferCountOperatorFunction(source) {\n return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));\n };\n}\n\nclass BufferCountOperator {\n constructor(bufferSize, startBufferEvery) {\n this.bufferSize = bufferSize;\n this.startBufferEvery = startBufferEvery;\n\n if (!startBufferEvery || bufferSize === startBufferEvery) {\n this.subscriberClass = BufferCountSubscriber;\n } else {\n this.subscriberClass = BufferSkipCountSubscriber;\n }\n }\n\n call(subscriber, source) {\n return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));\n }\n\n}\n\nclass BufferCountSubscriber extends Subscriber {\n constructor(destination, bufferSize) {\n super(destination);\n this.bufferSize = bufferSize;\n this.buffer = [];\n }\n\n _next(value) {\n const buffer = this.buffer;\n buffer.push(value);\n\n if (buffer.length == this.bufferSize) {\n this.destination.next(buffer);\n this.buffer = [];\n }\n }\n\n _complete() {\n const buffer = this.buffer;\n\n if (buffer.length > 0) {\n this.destination.next(buffer);\n }\n\n super._complete();\n }\n\n}\n\nclass BufferSkipCountSubscriber extends Subscriber {\n constructor(destination, bufferSize, startBufferEvery) {\n super(destination);\n this.bufferSize = bufferSize;\n this.startBufferEvery = startBufferEvery;\n this.buffers = [];\n this.count = 0;\n }\n\n _next(value) {\n const {\n bufferSize,\n startBufferEvery,\n buffers,\n count\n } = this;\n this.count++;\n\n if (count % startBufferEvery === 0) {\n buffers.push([]);\n }\n\n for (let i = buffers.length; i--;) {\n const buffer = buffers[i];\n buffer.push(value);\n\n if (buffer.length === bufferSize) {\n buffers.splice(i, 1);\n this.destination.next(buffer);\n }\n }\n }\n\n _complete() {\n const {\n buffers,\n destination\n } = this;\n\n while (buffers.length > 0) {\n let buffer = buffers.shift();\n\n if (buffer.length > 0) {\n destination.next(buffer);\n }\n }\n\n super._complete();\n }\n\n} //# sourceMappingURL=bufferCount.js.map","map":null,"metadata":{},"sourceType":"module"}
|