window.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 whenever
  6. * `windowBoundaries` emits.
  7. *
  8. * <span class="informal">It's like {@link buffer}, but emits a nested Observable
  9. * instead of an array.</span>
  10. *
  11. * <img src="./img/window.png" width="100%">
  12. *
  13. * Returns an Observable that emits windows of items it collects from the source
  14. * Observable. The output Observable emits connected, non-overlapping
  15. * windows. It emits the current window and opens a new one whenever the
  16. * Observable `windowBoundaries` emits an item. Because each window is an
  17. * Observable, the output is a higher-order Observable.
  18. *
  19. * @example <caption>In every window of 1 second each, emit at most 2 click events</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var interval = Rx.Observable.interval(1000);
  22. * var result = clicks.window(interval)
  23. * .map(win => win.take(2)) // each window has at most 2 emissions
  24. * .mergeAll(); // flatten the Observable-of-Observables
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * @see {@link windowCount}
  28. * @see {@link windowTime}
  29. * @see {@link windowToggle}
  30. * @see {@link windowWhen}
  31. * @see {@link buffer}
  32. *
  33. * @param {Observable<any>} windowBoundaries An Observable that completes the
  34. * previous window and starts a new window.
  35. * @return {Observable<Observable<T>>} An Observable of windows, which are
  36. * Observables emitting values of the source Observable.
  37. * @method window
  38. * @owner Observable
  39. */
  40. function window(windowBoundaries) {
  41. return operators_1.window(windowBoundaries)(this);
  42. }
  43. exports.window = window;
  44. //# sourceMappingURL=window.js.map