audit.js 2.1 KB

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