1 /** PURE_IMPORTS_START tslib,_Subscriber,_Subject PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscriber } from '../Subscriber';
4 import { Subject } from '../Subject';
5 export function windowCount(windowSize, startWindowEvery) {
6 if (startWindowEvery === void 0) {
9 return function windowCountOperatorFunction(source) {
10 return source.lift(new WindowCountOperator(windowSize, startWindowEvery));
13 var WindowCountOperator = /*@__PURE__*/ (function () {
14 function WindowCountOperator(windowSize, startWindowEvery) {
15 this.windowSize = windowSize;
16 this.startWindowEvery = startWindowEvery;
18 WindowCountOperator.prototype.call = function (subscriber, source) {
19 return source.subscribe(new WindowCountSubscriber(subscriber, this.windowSize, this.startWindowEvery));
21 return WindowCountOperator;
23 var WindowCountSubscriber = /*@__PURE__*/ (function (_super) {
24 tslib_1.__extends(WindowCountSubscriber, _super);
25 function WindowCountSubscriber(destination, windowSize, startWindowEvery) {
26 var _this = _super.call(this, destination) || this;
27 _this.destination = destination;
28 _this.windowSize = windowSize;
29 _this.startWindowEvery = startWindowEvery;
30 _this.windows = [new Subject()];
32 destination.next(_this.windows[0]);
35 WindowCountSubscriber.prototype._next = function (value) {
36 var startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize;
37 var destination = this.destination;
38 var windowSize = this.windowSize;
39 var windows = this.windows;
40 var len = windows.length;
41 for (var i = 0; i < len && !this.closed; i++) {
42 windows[i].next(value);
44 var c = this.count - windowSize + 1;
45 if (c >= 0 && c % startWindowEvery === 0 && !this.closed) {
46 windows.shift().complete();
48 if (++this.count % startWindowEvery === 0 && !this.closed) {
49 var window_1 = new Subject();
50 windows.push(window_1);
51 destination.next(window_1);
54 WindowCountSubscriber.prototype._error = function (err) {
55 var windows = this.windows;
57 while (windows.length > 0 && !this.closed) {
58 windows.shift().error(err);
61 this.destination.error(err);
63 WindowCountSubscriber.prototype._complete = function () {
64 var windows = this.windows;
66 while (windows.length > 0 && !this.closed) {
67 windows.shift().complete();
70 this.destination.complete();
72 WindowCountSubscriber.prototype._unsubscribe = function () {
76 return WindowCountSubscriber;
78 //# sourceMappingURL=windowCount.js.map