[6a3a178] | 1 | /** PURE_IMPORTS_START tslib,_Subscriber,_util_ArgumentOutOfRangeError PURE_IMPORTS_END */
|
---|
| 2 | import * as tslib_1 from "tslib";
|
---|
| 3 | import { Subscriber } from '../Subscriber';
|
---|
| 4 | import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
|
---|
| 5 | export function skipLast(count) {
|
---|
| 6 | return function (source) { return source.lift(new SkipLastOperator(count)); };
|
---|
| 7 | }
|
---|
| 8 | var SkipLastOperator = /*@__PURE__*/ (function () {
|
---|
| 9 | function SkipLastOperator(_skipCount) {
|
---|
| 10 | this._skipCount = _skipCount;
|
---|
| 11 | if (this._skipCount < 0) {
|
---|
| 12 | throw new ArgumentOutOfRangeError;
|
---|
| 13 | }
|
---|
| 14 | }
|
---|
| 15 | SkipLastOperator.prototype.call = function (subscriber, source) {
|
---|
| 16 | if (this._skipCount === 0) {
|
---|
| 17 | return source.subscribe(new Subscriber(subscriber));
|
---|
| 18 | }
|
---|
| 19 | else {
|
---|
| 20 | return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
|
---|
| 21 | }
|
---|
| 22 | };
|
---|
| 23 | return SkipLastOperator;
|
---|
| 24 | }());
|
---|
| 25 | var SkipLastSubscriber = /*@__PURE__*/ (function (_super) {
|
---|
| 26 | tslib_1.__extends(SkipLastSubscriber, _super);
|
---|
| 27 | function SkipLastSubscriber(destination, _skipCount) {
|
---|
| 28 | var _this = _super.call(this, destination) || this;
|
---|
| 29 | _this._skipCount = _skipCount;
|
---|
| 30 | _this._count = 0;
|
---|
| 31 | _this._ring = new Array(_skipCount);
|
---|
| 32 | return _this;
|
---|
| 33 | }
|
---|
| 34 | SkipLastSubscriber.prototype._next = function (value) {
|
---|
| 35 | var skipCount = this._skipCount;
|
---|
| 36 | var count = this._count++;
|
---|
| 37 | if (count < skipCount) {
|
---|
| 38 | this._ring[count] = value;
|
---|
| 39 | }
|
---|
| 40 | else {
|
---|
| 41 | var currentIndex = count % skipCount;
|
---|
| 42 | var ring = this._ring;
|
---|
| 43 | var oldValue = ring[currentIndex];
|
---|
| 44 | ring[currentIndex] = value;
|
---|
| 45 | this.destination.next(oldValue);
|
---|
| 46 | }
|
---|
| 47 | };
|
---|
| 48 | return SkipLastSubscriber;
|
---|
| 49 | }(Subscriber));
|
---|
| 50 | //# sourceMappingURL=skipLast.js.map
|
---|