e2d718ccfadb1f2f4a23d13f7afabbf21fae62915cd097f88247c02def97c75fbe69e33f8b5417ecf1fce91d689b9b57449ad4a8130189bed81bb5c983948f 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { MonoTypeOperatorFunction, ObservableInput } from '../types';
  2. /**
  3. * Emits the most recently emitted value from the source Observable whenever
  4. * another Observable, the `notifier`, emits.
  5. *
  6. * <span class="informal">It's like {@link sampleTime}, but samples whenever
  7. * the `notifier` `ObservableInput` emits something.</span>
  8. *
  9. * ![](sample.png)
  10. *
  11. * Whenever the `notifier` `ObservableInput` emits a value, `sample`
  12. * looks at the source Observable and emits whichever value it has most recently
  13. * emitted since the previous sampling, unless the source has not emitted
  14. * anything since the previous sampling. The `notifier` is subscribed to as soon
  15. * as the output Observable is subscribed.
  16. *
  17. * ## Example
  18. *
  19. * On every click, sample the most recent `seconds` timer
  20. *
  21. * ```ts
  22. * import { fromEvent, interval, sample } from 'rxjs';
  23. *
  24. * const seconds = interval(1000);
  25. * const clicks = fromEvent(document, 'click');
  26. * const result = seconds.pipe(sample(clicks));
  27. *
  28. * result.subscribe(x => console.log(x));
  29. * ```
  30. *
  31. * @see {@link audit}
  32. * @see {@link debounce}
  33. * @see {@link sampleTime}
  34. * @see {@link throttle}
  35. *
  36. * @param notifier The `ObservableInput` to use for sampling the
  37. * source Observable.
  38. * @return A function that returns an Observable that emits the results of
  39. * sampling the values emitted by the source Observable whenever the notifier
  40. * Observable emits value or completes.
  41. */
  42. export declare function sample<T>(notifier: ObservableInput<any>): MonoTypeOperatorFunction<T>;
  43. //# sourceMappingURL=sample.d.ts.map