Front end of the Slack clone application.

bufferToggle.d.ts 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Observable, SubscribableOrPromise } from '../Observable';
  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. * <img src="./img/bufferToggle.png" width="100%">
  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 <caption>Every other second, emit the click events from the next 500ms</caption>
  17. * var clicks = Rx.Observable.fromEvent(document, 'click');
  18. * var openings = Rx.Observable.interval(1000);
  19. * var buffered = clicks.bufferToggle(openings, i =>
  20. * i % 2 ? Rx.Observable.interval(500) : Rx.Observable.empty()
  21. * );
  22. * buffered.subscribe(x => console.log(x));
  23. *
  24. * @see {@link buffer}
  25. * @see {@link bufferCount}
  26. * @see {@link bufferTime}
  27. * @see {@link bufferWhen}
  28. * @see {@link windowToggle}
  29. *
  30. * @param {SubscribableOrPromise<O>} openings A Subscribable or Promise of notifications to start new
  31. * buffers.
  32. * @param {function(value: O): SubscribableOrPromise} closingSelector A function that takes
  33. * the value emitted by the `openings` observable and returns a Subscribable or Promise,
  34. * which, when it emits, signals that the associated buffer should be emitted
  35. * and cleared.
  36. * @return {Observable<T[]>} An observable of arrays of buffered values.
  37. * @method bufferToggle
  38. * @owner Observable
  39. */
  40. export declare function bufferToggle<T, O>(this: Observable<T>, openings: SubscribableOrPromise<O>, closingSelector: (value: O) => SubscribableOrPromise<any>): Observable<T[]>;