| 1 |
"use strict"; |
| 2 |
var __values = (this && this.__values) || function(o) { |
| 3 |
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; |
| 4 |
if (m) return m.call(o); |
| 5 |
if (o && typeof o.length === "number") return { |
| 6 |
next: function () { |
| 7 |
if (o && i >= o.length) o = void 0; |
| 8 |
return { value: o && o[i++], done: !o }; |
| 9 |
} |
| 10 |
}; |
| 11 |
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); |
| 12 |
}; |
| 13 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 14 |
exports.windowCount = void 0; |
| 15 |
var Subject_1 = require("../Subject"); |
| 16 |
var lift_1 = require("../util/lift"); |
| 17 |
var OperatorSubscriber_1 = require("./OperatorSubscriber"); |
| 18 |
function windowCount(windowSize, startWindowEvery) { |
| 19 |
if (startWindowEvery === void 0) { startWindowEvery = 0; } |
| 20 |
var startEvery = startWindowEvery > 0 ? startWindowEvery : windowSize; |
| 21 |
return lift_1.operate(function (source, subscriber) { |
| 22 |
var windows = [new Subject_1.Subject()]; |
| 23 |
var starts = []; |
| 24 |
var count = 0; |
| 25 |
subscriber.next(windows[0].asObservable()); |
| 26 |
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) { |
| 27 |
var e_1, _a; |
| 28 |
try { |
| 29 |
for (var windows_1 = __values(windows), windows_1_1 = windows_1.next(); !windows_1_1.done; windows_1_1 = windows_1.next()) { |
| 30 |
var window_1 = windows_1_1.value; |
| 31 |
window_1.next(value); |
| 32 |
} |
| 33 |
} |
| 34 |
catch (e_1_1) { e_1 = { error: e_1_1 }; } |
| 35 |
finally { |
| 36 |
try { |
| 37 |
if (windows_1_1 && !windows_1_1.done && (_a = windows_1.return)) _a.call(windows_1); |
| 38 |
} |
| 39 |
finally { if (e_1) throw e_1.error; } |
| 40 |
} |
| 41 |
var c = count - windowSize + 1; |
| 42 |
if (c >= 0 && c % startEvery === 0) { |
| 43 |
windows.shift().complete(); |
| 44 |
} |
| 45 |
if (++count % startEvery === 0) { |
| 46 |
var window_2 = new Subject_1.Subject(); |
| 47 |
windows.push(window_2); |
| 48 |
subscriber.next(window_2.asObservable()); |
| 49 |
} |
| 50 |
}, function () { |
| 51 |
while (windows.length > 0) { |
| 52 |
windows.shift().complete(); |
| 53 |
} |
| 54 |
subscriber.complete(); |
| 55 |
}, function (err) { |
| 56 |
while (windows.length > 0) { |
| 57 |
windows.shift().error(err); |
| 58 |
} |
| 59 |
subscriber.error(err); |
| 60 |
}, function () { |
| 61 |
starts = null; |
| 62 |
windows = null; |
| 63 |
})); |
| 64 |
}); |
| 65 |
} |
| 66 |
exports.windowCount = windowCount; |
| 67 |
//# sourceMappingURL=windowCount.js.map |