debounce.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { SubscribableOrPromise } from '../Observable';
  2. import { MonoTypeOperatorFunction } from '../interfaces';
  3. /**
  4. * Emits a value from the source Observable only after a particular time span
  5. * determined by another Observable has passed without another source emission.
  6. *
  7. * <span class="informal">It's like {@link debounceTime}, but the time span of
  8. * emission silence is determined by a second Observable.</span>
  9. *
  10. * <img src="./img/debounce.png" width="100%">
  11. *
  12. * `debounce` delays values emitted by the source Observable, but drops previous
  13. * pending delayed emissions if a new value arrives on the source Observable.
  14. * This operator keeps track of the most recent value from the source
  15. * Observable, and spawns a duration Observable by calling the
  16. * `durationSelector` function. The value is emitted only when the duration
  17. * Observable emits a value or completes, and if no other value was emitted on
  18. * the source Observable since the duration Observable was spawned. If a new
  19. * value appears before the duration Observable emits, the previous value will
  20. * be dropped and will not be emitted on the output Observable.
  21. *
  22. * Like {@link debounceTime}, this is a rate-limiting operator, and also a
  23. * delay-like operator since output emissions do not necessarily occur at the
  24. * same time as they did on the source Observable.
  25. *
  26. * @example <caption>Emit the most recent click after a burst of clicks</caption>
  27. * var clicks = Rx.Observable.fromEvent(document, 'click');
  28. * var result = clicks.debounce(() => Rx.Observable.interval(1000));
  29. * result.subscribe(x => console.log(x));
  30. *
  31. * @see {@link audit}
  32. * @see {@link debounceTime}
  33. * @see {@link delayWhen}
  34. * @see {@link throttle}
  35. *
  36. * @param {function(value: T): SubscribableOrPromise} durationSelector A function
  37. * that receives a value from the source Observable, for computing the timeout
  38. * duration for each source value, returned as an Observable or a Promise.
  39. * @return {Observable} An Observable that delays the emissions of the source
  40. * Observable by the specified duration Observable returned by
  41. * `durationSelector`, and may drop some values if they occur too frequently.
  42. * @method debounce
  43. * @owner Observable
  44. */
  45. export declare function debounce<T>(durationSelector: (value: T) => SubscribableOrPromise<number>): MonoTypeOperatorFunction<T>;