windowCount.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Branch out the source Observable values as a nested Observable with each
  6. * nested Observable emitting at most `windowSize` values.
  7. *
  8. * <span class="informal">It's like {@link bufferCount}, but emits a nested
  9. * Observable instead of an array.</span>
  10. *
  11. * <img src="./img/windowCount.png" width="100%">
  12. *
  13. * Returns an Observable that emits windows of items it collects from the source
  14. * Observable. The output Observable emits windows every `startWindowEvery`
  15. * items, each containing no more than `windowSize` items. When the source
  16. * Observable completes or encounters an error, the output Observable emits
  17. * the current window and propagates the notification from the source
  18. * Observable. If `startWindowEvery` is not provided, then new windows are
  19. * started immediately at the start of the source and when each window completes
  20. * with size `windowSize`.
  21. *
  22. * @example <caption>Ignore every 3rd click event, starting from the first one</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var result = clicks.windowCount(3)
  25. * .map(win => win.skip(1)) // skip first of every 3 clicks
  26. * .mergeAll(); // flatten the Observable-of-Observables
  27. * result.subscribe(x => console.log(x));
  28. *
  29. * @example <caption>Ignore every 3rd click event, starting from the third one</caption>
  30. * var clicks = Rx.Observable.fromEvent(document, 'click');
  31. * var result = clicks.windowCount(2, 3)
  32. * .mergeAll(); // flatten the Observable-of-Observables
  33. * result.subscribe(x => console.log(x));
  34. *
  35. * @see {@link window}
  36. * @see {@link windowTime}
  37. * @see {@link windowToggle}
  38. * @see {@link windowWhen}
  39. * @see {@link bufferCount}
  40. *
  41. * @param {number} windowSize The maximum number of values emitted by each
  42. * window.
  43. * @param {number} [startWindowEvery] Interval at which to start a new window.
  44. * For example if `startWindowEvery` is `2`, then a new window will be started
  45. * on every other value from the source. A new window is started at the
  46. * beginning of the source by default.
  47. * @return {Observable<Observable<T>>} An Observable of windows, which in turn
  48. * are Observable of values.
  49. * @method windowCount
  50. * @owner Observable
  51. */
  52. function windowCount(windowSize, startWindowEvery) {
  53. if (startWindowEvery === void 0) { startWindowEvery = 0; }
  54. return operators_1.windowCount(windowSize, startWindowEvery)(this);
  55. }
  56. exports.windowCount = windowCount;
  57. //# sourceMappingURL=windowCount.js.map