Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

bufferToggle.d.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { OperatorFunction, SubscribableOrPromise } 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, EMPTY } from 'rxjs';
  22. * import { bufferToggle } from 'rxjs/operators';
  23. *
  24. * const clicks = fromEvent(document, 'click');
  25. * const openings = interval(1000);
  26. * const buffered = clicks.pipe(bufferToggle(openings, i =>
  27. * i % 2 ? interval(500) : EMPTY
  28. * ));
  29. * buffered.subscribe(x => console.log(x));
  30. * ```
  31. *
  32. * @see {@link buffer}
  33. * @see {@link bufferCount}
  34. * @see {@link bufferTime}
  35. * @see {@link bufferWhen}
  36. * @see {@link windowToggle}
  37. *
  38. * @param {SubscribableOrPromise<O>} openings A Subscribable or Promise of notifications to start new
  39. * buffers.
  40. * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes
  41. * the value emitted by the `openings` observable and returns a Subscribable or Promise,
  42. * which, when it emits, signals that the associated buffer should be emitted
  43. * and cleared.
  44. * @return {Observable<T[]>} An observable of arrays of buffered values.
  45. * @method bufferToggle
  46. * @owner Observable
  47. */
  48. export declare function bufferToggle<T, O>(openings: SubscribableOrPromise<O>, closingSelector: (value: O) => SubscribableOrPromise<any>): OperatorFunction<T, T[]>;