[6a3a178] | 1 | import { Subscriber } from '../Subscriber';
|
---|
| 2 | import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
|
---|
| 3 | export function skipLast(count) {
|
---|
| 4 | return (source) => source.lift(new SkipLastOperator(count));
|
---|
| 5 | }
|
---|
| 6 | class SkipLastOperator {
|
---|
| 7 | constructor(_skipCount) {
|
---|
| 8 | this._skipCount = _skipCount;
|
---|
| 9 | if (this._skipCount < 0) {
|
---|
| 10 | throw new ArgumentOutOfRangeError;
|
---|
| 11 | }
|
---|
| 12 | }
|
---|
| 13 | call(subscriber, source) {
|
---|
| 14 | if (this._skipCount === 0) {
|
---|
| 15 | return source.subscribe(new Subscriber(subscriber));
|
---|
| 16 | }
|
---|
| 17 | else {
|
---|
| 18 | return source.subscribe(new SkipLastSubscriber(subscriber, this._skipCount));
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 | class SkipLastSubscriber extends Subscriber {
|
---|
| 23 | constructor(destination, _skipCount) {
|
---|
| 24 | super(destination);
|
---|
| 25 | this._skipCount = _skipCount;
|
---|
| 26 | this._count = 0;
|
---|
| 27 | this._ring = new Array(_skipCount);
|
---|
| 28 | }
|
---|
| 29 | _next(value) {
|
---|
| 30 | const skipCount = this._skipCount;
|
---|
| 31 | const count = this._count++;
|
---|
| 32 | if (count < skipCount) {
|
---|
| 33 | this._ring[count] = value;
|
---|
| 34 | }
|
---|
| 35 | else {
|
---|
| 36 | const currentIndex = count % skipCount;
|
---|
| 37 | const ring = this._ring;
|
---|
| 38 | const oldValue = ring[currentIndex];
|
---|
| 39 | ring[currentIndex] = value;
|
---|
| 40 | this.destination.next(oldValue);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | //# sourceMappingURL=skipLast.js.map |
---|