debounce.js 2.3 KB

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