2 var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subscriber_1 = require("../Subscriber");
17 function bufferCount(bufferSize, startBufferEvery) {
18 if (startBufferEvery === void 0) { startBufferEvery = null; }
19 return function bufferCountOperatorFunction(source) {
20 return source.lift(new BufferCountOperator(bufferSize, startBufferEvery));
23 exports.bufferCount = bufferCount;
24 var BufferCountOperator = (function () {
25 function BufferCountOperator(bufferSize, startBufferEvery) {
26 this.bufferSize = bufferSize;
27 this.startBufferEvery = startBufferEvery;
28 if (!startBufferEvery || bufferSize === startBufferEvery) {
29 this.subscriberClass = BufferCountSubscriber;
32 this.subscriberClass = BufferSkipCountSubscriber;
35 BufferCountOperator.prototype.call = function (subscriber, source) {
36 return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery));
38 return BufferCountOperator;
40 var BufferCountSubscriber = (function (_super) {
41 __extends(BufferCountSubscriber, _super);
42 function BufferCountSubscriber(destination, bufferSize) {
43 var _this = _super.call(this, destination) || this;
44 _this.bufferSize = bufferSize;
48 BufferCountSubscriber.prototype._next = function (value) {
49 var buffer = this.buffer;
51 if (buffer.length == this.bufferSize) {
52 this.destination.next(buffer);
56 BufferCountSubscriber.prototype._complete = function () {
57 var buffer = this.buffer;
58 if (buffer.length > 0) {
59 this.destination.next(buffer);
61 _super.prototype._complete.call(this);
63 return BufferCountSubscriber;
64 }(Subscriber_1.Subscriber));
65 var BufferSkipCountSubscriber = (function (_super) {
66 __extends(BufferSkipCountSubscriber, _super);
67 function BufferSkipCountSubscriber(destination, bufferSize, startBufferEvery) {
68 var _this = _super.call(this, destination) || this;
69 _this.bufferSize = bufferSize;
70 _this.startBufferEvery = startBufferEvery;
75 BufferSkipCountSubscriber.prototype._next = function (value) {
76 var _a = this, bufferSize = _a.bufferSize, startBufferEvery = _a.startBufferEvery, buffers = _a.buffers, count = _a.count;
78 if (count % startBufferEvery === 0) {
81 for (var i = buffers.length; i--;) {
82 var buffer = buffers[i];
84 if (buffer.length === bufferSize) {
86 this.destination.next(buffer);
90 BufferSkipCountSubscriber.prototype._complete = function () {
91 var _a = this, buffers = _a.buffers, destination = _a.destination;
92 while (buffers.length > 0) {
93 var buffer = buffers.shift();
94 if (buffer.length > 0) {
95 destination.next(buffer);
98 _super.prototype._complete.call(this);
100 return BufferSkipCountSubscriber;
101 }(Subscriber_1.Subscriber));
102 //# sourceMappingURL=bufferCount.js.map