skip.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /** PURE_IMPORTS_START .._Subscriber PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subscriber } from '../Subscriber';
  10. /**
  11. * Returns an Observable that skips the first `count` items emitted by the source Observable.
  12. *
  13. * <img src="./img/skip.png" width="100%">
  14. *
  15. * @param {Number} count - The number of times, items emitted by source Observable should be skipped.
  16. * @return {Observable} An Observable that skips values emitted by the source Observable.
  17. *
  18. * @method skip
  19. * @owner Observable
  20. */
  21. export function skip(count) {
  22. return function (source) { return source.lift(new SkipOperator(count)); };
  23. }
  24. var SkipOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  25. function SkipOperator(total) {
  26. this.total = total;
  27. }
  28. SkipOperator.prototype.call = function (subscriber, source) {
  29. return source.subscribe(new SkipSubscriber(subscriber, this.total));
  30. };
  31. return SkipOperator;
  32. }());
  33. /**
  34. * We need this JSDoc comment for affecting ESDoc.
  35. * @ignore
  36. * @extends {Ignored}
  37. */
  38. var SkipSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  39. __extends(SkipSubscriber, _super);
  40. function SkipSubscriber(destination, total) {
  41. _super.call(this, destination);
  42. this.total = total;
  43. this.count = 0;
  44. }
  45. SkipSubscriber.prototype._next = function (x) {
  46. if (++this.count > this.total) {
  47. this.destination.next(x);
  48. }
  49. };
  50. return SkipSubscriber;
  51. }(Subscriber));
  52. //# sourceMappingURL=skip.js.map