blob: ab9f14211fe3b5d730e5385688a63e8ca288c0ee [file] [log] [blame]
/** PURE_IMPORTS_START tslib,_Subscriber,_util_ArgumentOutOfRangeError PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { Subscriber } from '../Subscriber';
import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
export function skipLast(count) {
return function (source) { return source.lift(new SkipLastOperator(count)); };
}
var SkipLastOperator = /*@__PURE__*/ (function () {
function SkipLastOperator(_skipCount) {
this._skipCount = _skipCount;
if (this._skipCount < 0) {
throw new ArgumentOutOfRangeError;
}
}
SkipLastOperator.prototype.call = function (subscriber, source) {
if (this._skipCount === 0) {
return source.subscribe(new Subscriber(subscriber));
}
else {
return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
}
};
return SkipLastOperator;
}());
var SkipLastSubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(SkipLastSubscriber, _super);
function SkipLastSubscriber(destination, _skipCount) {
var _this = _super.call(this, destination) || this;
_this._skipCount = _skipCount;
_this._count = 0;
_this._ring = new Array(_skipCount);
return _this;
}
SkipLastSubscriber.prototype._next = function (value) {
var skipCount = this._skipCount;
var count = this._count++;
if (count < skipCount) {
this._ring[count] = value;
}
else {
var currentIndex = count % skipCount;
var ring = this._ring;
var oldValue = ring[currentIndex];
ring[currentIndex] = value;
this.destination.next(oldValue);
}
};
return SkipLastSubscriber;
}(Subscriber));
//# sourceMappingURL=skipLast.js.map