1 import { Subscriber } from '../Subscriber';
2 import { ArgumentOutOfRangeError } from '../util/ArgumentOutOfRangeError';
3 import { empty } from '../observable/empty';
4 export function takeLast(count) {
5 return function takeLastOperatorFunction(source) {
10 return source.lift(new TakeLastOperator(count));
14 class TakeLastOperator {
18 throw new ArgumentOutOfRangeError;
21 call(subscriber, source) {
22 return source.subscribe(new TakeLastSubscriber(subscriber, this.total));
25 class TakeLastSubscriber extends Subscriber {
26 constructor(destination, total) {
29 this.ring = new Array();
33 const ring = this.ring;
34 const total = this.total;
35 const count = this.count++;
36 if (ring.length < total) {
40 const index = count % total;
45 const destination = this.destination;
46 let count = this.count;
48 const total = this.count >= this.total ? this.total : this.count;
49 const ring = this.ring;
50 for (let i = 0; i < total; i++) {
51 const idx = (count++) % total;
52 destination.next(ring[idx]);
55 destination.complete();
58 //# sourceMappingURL=takeLast.js.map