sample.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Emits the most recently emitted value from the source Observable whenever
  6. * another Observable, the `notifier`, emits.
  7. *
  8. * <span class="informal">It's like {@link sampleTime}, but samples whenever
  9. * the `notifier` Observable emits something.</span>
  10. *
  11. * <img src="./img/sample.png" width="100%">
  12. *
  13. * Whenever the `notifier` Observable emits a value or completes, `sample`
  14. * looks at the source Observable and emits whichever value it has most recently
  15. * emitted since the previous sampling, unless the source has not emitted
  16. * anything since the previous sampling. The `notifier` is subscribed to as soon
  17. * as the output Observable is subscribed.
  18. *
  19. * @example <caption>On every click, sample the most recent "seconds" timer</caption>
  20. * var seconds = Rx.Observable.interval(1000);
  21. * var clicks = Rx.Observable.fromEvent(document, 'click');
  22. * var result = seconds.sample(clicks);
  23. * result.subscribe(x => console.log(x));
  24. *
  25. * @see {@link audit}
  26. * @see {@link debounce}
  27. * @see {@link sampleTime}
  28. * @see {@link throttle}
  29. *
  30. * @param {Observable<any>} notifier The Observable to use for sampling the
  31. * source Observable.
  32. * @return {Observable<T>} An Observable that emits the results of sampling the
  33. * values emitted by the source Observable whenever the notifier Observable
  34. * emits value or completes.
  35. * @method sample
  36. * @owner Observable
  37. */
  38. function sample(notifier) {
  39. return operators_1.sample(notifier)(this);
  40. }
  41. exports.sample = sample;
  42. //# sourceMappingURL=sample.js.map