bufferToggle.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Buffers the source Observable values starting from an emission from
  6. * `openings` and ending when the output of `closingSelector` emits.
  7. *
  8. * <span class="informal">Collects values from the past as an array. Starts
  9. * collecting only when `opening` emits, and calls the `closingSelector`
  10. * function to get an Observable that tells when to close the buffer.</span>
  11. *
  12. * <img src="./img/bufferToggle.png" width="100%">
  13. *
  14. * Buffers values from the source by opening the buffer via signals from an
  15. * Observable provided to `openings`, and closing and sending the buffers when
  16. * a Subscribable or Promise returned by the `closingSelector` function emits.
  17. *
  18. * @example <caption>Every other second, emit the click events from the next 500ms</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var openings = Rx.Observable.interval(1000);
  21. * var buffered = clicks.bufferToggle(openings, i =>
  22. * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
  23. * );
  24. * buffered.subscribe(x => console.log(x));
  25. *
  26. * @see {@link buffer}
  27. * @see {@link bufferCount}
  28. * @see {@link bufferTime}
  29. * @see {@link bufferWhen}
  30. * @see {@link windowToggle}
  31. *
  32. * @param {SubscribableOrPromise<O>} openings A Subscribable or Promise of notifications to start new
  33. * buffers.
  34. * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes
  35. * the value emitted by the `openings` observable and returns a Subscribable or Promise,
  36. * which, when it emits, signals that the associated buffer should be emitted
  37. * and cleared.
  38. * @return {Observable<T[]>} An observable of arrays of buffered values.
  39. * @method bufferToggle
  40. * @owner Observable
  41. */
  42. function bufferToggle(openings, closingSelector) {
  43. return operators_1.bufferToggle(openings, closingSelector)(this);
  44. }
  45. exports.bufferToggle = bufferToggle;
  46. //# sourceMappingURL=bufferToggle.js.map