sampleTime.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 the most recently emitted value from the source Observable within
  7. * periodic time intervals.
  8. *
  9. * <span class="informal">Samples the source Observable at periodic time
  10. * intervals, emitting what it samples.</span>
  11. *
  12. * <img src="./img/sampleTime.png" width="100%">
  13. *
  14. * `sampleTime` periodically looks at the source Observable and emits whichever
  15. * value it has most recently emitted since the previous sampling, unless the
  16. * source has not emitted anything since the previous sampling. The sampling
  17. * happens periodically in time every `period` milliseconds (or the time unit
  18. * defined by the optional `scheduler` argument). The sampling starts as soon as
  19. * the output Observable is subscribed.
  20. *
  21. * @example <caption>Every second, emit the most recent click at most once</caption>
  22. * var clicks = Rx.Observable.fromEvent(document, 'click');
  23. * var result = clicks.sampleTime(1000);
  24. * result.subscribe(x => console.log(x));
  25. *
  26. * @see {@link auditTime}
  27. * @see {@link debounceTime}
  28. * @see {@link delay}
  29. * @see {@link sample}
  30. * @see {@link throttleTime}
  31. *
  32. * @param {number} period The sampling period expressed in milliseconds or the
  33. * time unit determined internally by the optional `scheduler`.
  34. * @param {Scheduler} [scheduler=asyncScheduler] The {@link SchedulerLike} to use for
  35. * managing the timers that handle the sampling.
  36. * @return {Observable<T>} An Observable that emits the results of sampling the
  37. * values emitted by the source Observable at the specified time interval.
  38. * @method sampleTime
  39. * @owner Observable
  40. */
  41. function sampleTime(period, scheduler) {
  42. if (scheduler === void 0) { scheduler = rxjs_1.asyncScheduler; }
  43. return operators_1.sampleTime(period, scheduler)(this);
  44. }
  45. exports.sampleTime = sampleTime;
  46. //# sourceMappingURL=sampleTime.js.map