windowToggle.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 starting from
  6. * an emission from `openings` and ending when the output of `closingSelector`
  7. * emits.
  8. *
  9. * <span class="informal">It's like {@link bufferToggle}, but emits a nested
  10. * Observable instead of an array.</span>
  11. *
  12. * <img src="./img/windowToggle.png" width="100%">
  13. *
  14. * Returns an Observable that emits windows of items it collects from the source
  15. * Observable. The output Observable emits windows that contain those items
  16. * emitted by the source Observable between the time when the `openings`
  17. * Observable emits an item and when the Observable returned by
  18. * `closingSelector` emits an item.
  19. *
  20. * @example <caption>Every other second, emit the click events from the next 500ms</caption>
  21. * var clicks = Rx.Observable.fromEvent(document, 'click');
  22. * var openings = Rx.Observable.interval(1000);
  23. * var result = clicks.windowToggle(openings, i =>
  24. * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
  25. * ).mergeAll();
  26. * result.subscribe(x => console.log(x));
  27. *
  28. * @see {@link window}
  29. * @see {@link windowCount}
  30. * @see {@link windowTime}
  31. * @see {@link windowWhen}
  32. * @see {@link bufferToggle}
  33. *
  34. * @param {Observable<O>} openings An observable of notifications to start new
  35. * windows.
  36. * @param {function(value: O): Observable} closingSelector A function that takes
  37. * the value emitted by the `openings` observable and returns an Observable,
  38. * which, when it emits (either `next` or `complete`), signals that the
  39. * associated window should complete.
  40. * @return {Observable<Observable<T>>} An observable of windows, which in turn
  41. * are Observables.
  42. * @method windowToggle
  43. * @owner Observable
  44. */
  45. function windowToggle(openings, closingSelector) {
  46. return operators_1.windowToggle(openings, closingSelector)(this);
  47. }
  48. exports.windowToggle = windowToggle;
  49. //# sourceMappingURL=windowToggle.js.map