takeLast.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Emits only the last `count` values emitted by the source Observable.
  6. *
  7. * <span class="informal">Remembers the latest `count` values, then emits those
  8. * only when the source completes.</span>
  9. *
  10. * <img src="./img/takeLast.png" width="100%">
  11. *
  12. * `takeLast` returns an Observable that emits at most the last `count` values
  13. * emitted by the source Observable. If the source emits fewer than `count`
  14. * values then all of its values are emitted. This operator must wait until the
  15. * `complete` notification emission from the source in order to emit the `next`
  16. * values on the output Observable, because otherwise it is impossible to know
  17. * whether or not more values will be emitted on the source. For this reason,
  18. * all values are emitted synchronously, followed by the complete notification.
  19. *
  20. * @example <caption>Take the last 3 values of an Observable with many values</caption>
  21. * var many = Rx.Observable.range(1, 100);
  22. * var lastThree = many.takeLast(3);
  23. * lastThree.subscribe(x => console.log(x));
  24. *
  25. * @see {@link take}
  26. * @see {@link takeUntil}
  27. * @see {@link takeWhile}
  28. * @see {@link skip}
  29. *
  30. * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an
  31. * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
  32. *
  33. * @param {number} count The maximum number of values to emit from the end of
  34. * the sequence of values emitted by the source Observable.
  35. * @return {Observable<T>} An Observable that emits at most the last count
  36. * values emitted by the source Observable.
  37. * @method takeLast
  38. * @owner Observable
  39. */
  40. function takeLast(count) {
  41. return operators_1.takeLast(count)(this);
  42. }
  43. exports.takeLast = takeLast;
  44. //# sourceMappingURL=takeLast.js.map