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