1 import { Subscriber } from '../Subscriber';
2 import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
3 export function skipLast(count) {
4 return (source) => source.lift(new SkipLastOperator(count));
6 class SkipLastOperator {
7 constructor(_skipCount) {
8 this._skipCount = _skipCount;
9 if (this._skipCount < 0) {
10 throw new ArgumentOutOfRangeError;
13 call(subscriber, source) {
14 if (this._skipCount === 0) {
15 return source.subscribe(new Subscriber(subscriber));
18 return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
22 class SkipLastSubscriber extends Subscriber {
23 constructor(destination, _skipCount) {
25 this._skipCount = _skipCount;
27 this._ring = new Array(_skipCount);
30 const skipCount = this._skipCount;
31 const count = this._count++;
32 if (count < skipCount) {
33 this._ring[count] = value;
36 const currentIndex = count % skipCount;
37 const ring = this._ring;
38 const oldValue = ring[currentIndex];
39 ring[currentIndex] = value;
40 this.destination.next(oldValue);
44 //# sourceMappingURL=skipLast.js.map