skip.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Subscriber } from '../Subscriber';
  2. /**
  3. * Returns an Observable that skips the first `count` items emitted by the source Observable.
  4. *
  5. * <img src="./img/skip.png" width="100%">
  6. *
  7. * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
  8. * @return {Observable} An Observable that skips values emitted by the source Observable.
  9. *
  10. * @method skip
  11. * @owner Observable
  12. */
  13. export function skip(count) {
  14. return (source) => source.lift(new SkipOperator(count));
  15. }
  16. class SkipOperator {
  17. constructor(total) {
  18. this.total = total;
  19. }
  20. call(subscriber, source) {
  21. return source.subscribe(new SkipSubscriber(subscriber, this.total));
  22. }
  23. }
  24. /**
  25. * We need this JSDoc comment for affecting ESDoc.
  26. * @ignore
  27. * @extends {Ignored}
  28. */
  29. class SkipSubscriber extends Subscriber {
  30. constructor(destination, total) {
  31. super(destination);
  32. this.total = total;
  33. this.count = 0;
  34. }
  35. _next(x) {
  36. if (++this.count > this.total) {
  37. this.destination.next(x);
  38. }
  39. }
  40. }
  41. //# sourceMappingURL=skip.js.map