@reactivex/rxjs
Version:
Reactive Extensions for modern JavaScript
41 lines • 1.07 kB
JavaScript
import { Subscriber } from '../Subscriber';
/**
* Returns an Observable that skips `n` items emitted by an Observable.
*
* <img src="./img/skip.png" width="100%">
*
* @param {Number} the `n` of times, items emitted by source Observable should be skipped.
* @return {Observable} an Observable that skips values emitted by the source Observable.
*
* @method skip
* @owner Observable
*/
export function skip(total) {
return this.lift(new SkipOperator(total));
}
class SkipOperator {
constructor(total) {
this.total = total;
}
call(subscriber, source) {
return source._subscribe(new SkipSubscriber(subscriber, this.total));
}
}
/**
* We need this JSDoc comment for affecting ESDoc.
* @ignore
* @extends {Ignored}
*/
class SkipSubscriber extends Subscriber {
constructor(destination, total) {
super(destination);
this.total = total;
this.count = 0;
}
_next(x) {
if (++this.count > this.total) {
this.destination.next(x);
}
}
}
//# sourceMappingURL=skip.js.map