hugoWebsite/node_modules/rxjs/dist/cjs/internal/operators/takeLast.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-10-29 00:20:35 +02:00
"use strict";
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.takeLast = void 0;
var empty_1 = require("../observable/empty");
var lift_1 = require("../util/lift");
var OperatorSubscriber_1 = require("./OperatorSubscriber");
function takeLast(count) {
return count <= 0
? function () { return empty_1.EMPTY; }
: lift_1.operate(function (source, subscriber) {
var buffer = [];
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
buffer.push(value);
count < buffer.length && buffer.shift();
}, function () {
var e_1, _a;
try {
for (var buffer_1 = __values(buffer), buffer_1_1 = buffer_1.next(); !buffer_1_1.done; buffer_1_1 = buffer_1.next()) {
var value = buffer_1_1.value;
subscriber.next(value);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (buffer_1_1 && !buffer_1_1.done && (_a = buffer_1.return)) _a.call(buffer_1);
}
finally { if (e_1) throw e_1.error; }
}
subscriber.complete();
}, undefined, function () {
buffer = null;
}));
});
}
exports.takeLast = takeLast;
//# sourceMappingURL=takeLast.js.map