bufferWhen.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var bufferWhen_1 = require('../operators/bufferWhen');
  3. /**
  4. * Buffers the source Observable values, using a factory function of closing
  5. * Observables to determine when to close, emit, and reset the buffer.
  6. *
  7. * <span class="informal">Collects values from the past as an array. When it
  8. * starts collecting values, it calls a function that returns an Observable that
  9. * tells when to close the buffer and restart collecting.</span>
  10. *
  11. * <img src="./img/bufferWhen.png" width="100%">
  12. *
  13. * Opens a buffer immediately, then closes the buffer when the observable
  14. * returned by calling `closingSelector` function emits a value. When it closes
  15. * the buffer, it immediately opens a new buffer and repeats the process.
  16. *
  17. * @example <caption>Emit an array of the last clicks every [1-5] random seconds</caption>
  18. * var clicks = Rx.Observable.fromEvent(document, 'click');
  19. * var buffered = clicks.bufferWhen(() =>
  20. * Rx.Observable.interval(1000 + Math.random() * 4000)
  21. * );
  22. * buffered.subscribe(x => console.log(x));
  23. *
  24. * @see {@link buffer}
  25. * @see {@link bufferCount}
  26. * @see {@link bufferTime}
  27. * @see {@link bufferToggle}
  28. * @see {@link windowWhen}
  29. *
  30. * @param {function(): Observable} closingSelector A function that takes no
  31. * arguments and returns an Observable that signals buffer closure.
  32. * @return {Observable<T[]>} An observable of arrays of buffered values.
  33. * @method bufferWhen
  34. * @owner Observable
  35. */
  36. function bufferWhen(closingSelector) {
  37. return bufferWhen_1.bufferWhen(closingSelector)(this);
  38. }
  39. exports.bufferWhen = bufferWhen;
  40. //# sourceMappingURL=bufferWhen.js.map