debounceTime.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var rxjs_1 = require("rxjs");
  4. var operators_1 = require("rxjs/operators");
  5. /**
  6. * Emits a value from the source Observable only after a particular time span
  7. * has passed without another source emission.
  8. *
  9. * <span class="informal">It's like {@link delay}, but passes only the most
  10. * recent value from each burst of emissions.</span>
  11. *
  12. * <img src="./img/debounceTime.png" width="100%">
  13. *
  14. * `debounceTime` delays values emitted by the source Observable, but drops
  15. * previous pending delayed emissions if a new value arrives on the source
  16. * Observable. This operator keeps track of the most recent value from the
  17. * source Observable, and emits that only when `dueTime` enough time has passed
  18. * without any other value appearing on the source Observable. If a new value
  19. * appears before `dueTime` silence occurs, the previous value will be dropped
  20. * and will not be emitted on the output Observable.
  21. *
  22. * This is a rate-limiting operator, because it is impossible for more than one
  23. * value to be emitted in any time window of duration `dueTime`, but it is also
  24. * a delay-like operator since output emissions do not occur at the same time as
  25. * they did on the source Observable. Optionally takes a {@link IScheduler} for
  26. * managing timers.
  27. *
  28. * @example <caption>Emit the most recent click after a burst of clicks</caption>
  29. * var clicks = Rx.Observable.fromEvent(document, 'click');
  30. * var result = clicks.debounceTime(1000);
  31. * result.subscribe(x => console.log(x));
  32. *
  33. * @see {@link auditTime}
  34. * @see {@link debounce}
  35. * @see {@link delay}
  36. * @see {@link sampleTime}
  37. * @see {@link throttleTime}
  38. *
  39. * @param {number} dueTime The timeout duration in milliseconds (or the time
  40. * unit determined internally by the optional `scheduler`) for the window of
  41. * time required to wait for emission silence before emitting the most recent
  42. * source value.
  43. * @param {Scheduler} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
  44. * managing the timers that handle the timeout for each value.
  45. * @return {Observable} An Observable that delays the emissions of the source
  46. * Observable by the specified `dueTime`, and may drop some values if they occur
  47. * too frequently.
  48. * @method debounceTime
  49. * @owner Observable
  50. */
  51. function debounceTime(dueTime, scheduler) {
  52. if (scheduler === void 0) { scheduler = rxjs_1.asyncScheduler; }
  53. return operators_1.debounceTime(dueTime, scheduler)(this);
  54. }
  55. exports.debounceTime = debounceTime;
  56. //# sourceMappingURL=debounceTime.js.map