frontend/.pnpm-store/v3/files/4d/e330d55f018209d5bfa4007b71339d0132cd75e357dec6d3f671fe63d2e0362299706de71f4231ed4c3f64fcee6f14d68648f74a6be86cd8db03c770c387a7

44 lines
1.3 KiB
Plaintext

import { Subscriber } from '../Subscriber';
import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
export function skipLast(count) {
return (source) => source.lift(new SkipLastOperator(count));
}
class SkipLastOperator {
constructor(_skipCount) {
this._skipCount = _skipCount;
if (this._skipCount < 0) {
throw new ArgumentOutOfRangeError;
}
}
call(subscriber, source) {
if (this._skipCount === 0) {
return source.subscribe(new Subscriber(subscriber));
}
else {
return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
}
}
}
class SkipLastSubscriber extends Subscriber {
constructor(destination, _skipCount) {
super(destination);
this._skipCount = _skipCount;
this._count = 0;
this._ring = new Array(_skipCount);
}
_next(value) {
const skipCount = this._skipCount;
const count = this._count++;
if (count < skipCount) {
this._ring[count] = value;
}
else {
const currentIndex = count % skipCount;
const ring = this._ring;
const oldValue = ring[currentIndex];
ring[currentIndex] = value;
this.destination.next(oldValue);
}
}
}
//# sourceMappingURL=skipLast.js.map