Front end of the Slack clone application.

throttle.d.ts 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Observable, SubscribableOrPromise } from '../Observable';
  2. import { ThrottleConfig } from '../operators/throttle';
  3. /**
  4. * Emits a value from the source Observable, then ignores subsequent source
  5. * values for a duration determined by another Observable, then repeats this
  6. * process.
  7. *
  8. * <span class="informal">It's like {@link throttleTime}, but the silencing
  9. * duration is determined by a second Observable.</span>
  10. *
  11. * <img src="./img/throttle.png" width="100%">
  12. *
  13. * `throttle` emits the source Observable values on the output Observable
  14. * when its internal timer is disabled, and ignores source values when the timer
  15. * is enabled. Initially, the timer is disabled. As soon as the first source
  16. * value arrives, it is forwarded to the output Observable, and then the timer
  17. * is enabled by calling the `durationSelector` function with the source value,
  18. * which returns the "duration" Observable. When the duration Observable emits a
  19. * value or completes, the timer is disabled, and this process repeats for the
  20. * next source value.
  21. *
  22. * @example <caption>Emit clicks at a rate of at most one click per second</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var result = clicks.throttle(ev => Rx.Observable.interval(1000));
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * @see {@link audit}
  28. * @see {@link debounce}
  29. * @see {@link delayWhen}
  30. * @see {@link sample}
  31. * @see {@link throttleTime}
  32. *
  33. * @param {function(value: T): SubscribableOrPromise} durationSelector A function
  34. * that receives a value from the source Observable, for computing the silencing
  35. * duration for each source value, returned as an Observable or a Promise.
  36. * @param {Object} config a configuration object to define `leading` and `trailing` behavior. Defaults
  37. * to `{ leading: true, trailing: false }`.
  38. * @return {Observable<T>} An Observable that performs the throttle operation to
  39. * limit the rate of emissions from the source.
  40. * @method throttle
  41. * @owner Observable
  42. */
  43. export declare function throttle<T>(this: Observable<T>, durationSelector: (value: T) => SubscribableOrPromise<number>, config?: ThrottleConfig): Observable<T>;