audit.d.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Observable, SubscribableOrPromise } from '../Observable';
  2. /**
  3. * Ignores source values for a duration determined by another Observable, then
  4. * emits the most recent value from the source Observable, then repeats this
  5. * process.
  6. *
  7. * <span class="informal">It's like {@link auditTime}, but the silencing
  8. * duration is determined by a second Observable.</span>
  9. *
  10. * <img src="./img/audit.png" width="100%">
  11. *
  12. * `audit` is similar to `throttle`, but emits the last value from the silenced
  13. * time window, instead of the first value. `audit` emits the most recent value
  14. * from the source Observable on the output Observable as soon as its internal
  15. * timer becomes disabled, and ignores source values while the timer is enabled.
  16. * Initially, the timer is disabled. As soon as the first source value arrives,
  17. * the timer is enabled by calling the `durationSelector` function with the
  18. * source value, which returns the "duration" Observable. When the duration
  19. * Observable emits a value or completes, the timer is disabled, then the most
  20. * recent source value is emitted on the output Observable, and this process
  21. * repeats for the next source value.
  22. *
  23. * @example <caption>Emit clicks at a rate of at most one click per second</caption>
  24. * var clicks = Rx.Observable.fromEvent(document, 'click');
  25. * var result = clicks.audit(ev => Rx.Observable.interval(1000));
  26. * result.subscribe(x => console.log(x));
  27. *
  28. * @see {@link auditTime}
  29. * @see {@link debounce}
  30. * @see {@link delayWhen}
  31. * @see {@link sample}
  32. * @see {@link throttle}
  33. *
  34. * @param {function(value: T): SubscribableOrPromise} durationSelector A function
  35. * that receives a value from the source Observable, for computing the silencing
  36. * duration, returned as an Observable or a Promise.
  37. * @return {Observable<T>} An Observable that performs rate-limiting of
  38. * emissions from the source Observable.
  39. * @method audit
  40. * @owner Observable
  41. */
  42. export declare function audit<T>(this: Observable<T>, durationSelector: (value: T) => SubscribableOrPromise<any>): Observable<T>;