bufferWhen.d.ts 1.5KB

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