f1ecbba667763a1802637b704da1ba02b7a41aa93ae417f4e3e874138f3820af3286cf77081886340b461ac36c96bb2d9d182741c2c37aec3c43f37590ddcc 1.8 KB

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