Front end of the Slack clone application.

windowWhen.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** PURE_IMPORTS_START .._operators_windowWhen PURE_IMPORTS_END */
  2. import { windowWhen as higherOrder } from '../operators/windowWhen';
  3. /**
  4. * Branch out the source Observable values as a nested Observable using a
  5. * factory function of closing Observables to determine when to start a new
  6. * window.
  7. *
  8. * <span class="informal">It's like {@link bufferWhen}, but emits a nested
  9. * Observable instead of an array.</span>
  10. *
  11. * <img src="./img/windowWhen.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 windows.
  15. * It emits the current window and opens a new one whenever the Observable
  16. * produced by the specified `closingSelector` function emits an item. The first
  17. * window is opened immediately when subscribing to the output Observable.
  18. *
  19. * @example <caption>Emit only the first two clicks events in every window of [1-5] random seconds</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var result = clicks
  22. * .windowWhen(() => Rx.Observable.interval(1000 + Math.random() * 4000))
  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 window}
  28. * @see {@link windowCount}
  29. * @see {@link windowTime}
  30. * @see {@link windowToggle}
  31. * @see {@link bufferWhen}
  32. *
  33. * @param {function(): Observable} closingSelector A function that takes no
  34. * arguments and returns an Observable that signals (on either `next` or
  35. * `complete`) when to close the previous window and start a new one.
  36. * @return {Observable<Observable<T>>} An observable of windows, which in turn
  37. * are Observables.
  38. * @method windowWhen
  39. * @owner Observable
  40. */
  41. export function windowWhen(closingSelector) {
  42. return higherOrder(closingSelector)(this);
  43. }
  44. //# sourceMappingURL=windowWhen.js.map