delayWhen.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Delays the emission of items from the source Observable by a given time span
  6. * determined by the emissions of another Observable.
  7. *
  8. * <span class="informal">It's like {@link delay}, but the time span of the
  9. * delay duration is determined by a second Observable.</span>
  10. *
  11. * <img src="./img/delayWhen.png" width="100%">
  12. *
  13. * `delayWhen` time shifts each emitted value from the source Observable by a
  14. * time span determined by another Observable. When the source emits a value,
  15. * the `delayDurationSelector` function is called with the source value as
  16. * argument, and should return an Observable, called the "duration" Observable.
  17. * The source value is emitted on the output Observable only when the duration
  18. * Observable emits a value or completes.
  19. *
  20. * Optionally, `delayWhen` takes a second argument, `subscriptionDelay`, which
  21. * is an Observable. When `subscriptionDelay` emits its first value or
  22. * completes, the source Observable is subscribed to and starts behaving like
  23. * described in the previous paragraph. If `subscriptionDelay` is not provided,
  24. * `delayWhen` will subscribe to the source Observable as soon as the output
  25. * Observable is subscribed.
  26. *
  27. * @example <caption>Delay each click by a random amount of time, between 0 and 5 seconds</caption>
  28. * var clicks = Rx.Observable.fromEvent(document, 'click');
  29. * var delayedClicks = clicks.delayWhen(event =>
  30. * Rx.Observable.interval(Math.random() * 5000)
  31. * );
  32. * delayedClicks.subscribe(x => console.log(x));
  33. *
  34. * @see {@link debounce}
  35. * @see {@link delay}
  36. *
  37. * @param {function(value: T): Observable} delayDurationSelector A function that
  38. * returns an Observable for each value emitted by the source Observable, which
  39. * is then used to delay the emission of that item on the output Observable
  40. * until the Observable returned from this function emits a value.
  41. * @param {Observable} subscriptionDelay An Observable that triggers the
  42. * subscription to the source Observable once it emits any value.
  43. * @return {Observable} An Observable that delays the emissions of the source
  44. * Observable by an amount of time specified by the Observable returned by
  45. * `delayDurationSelector`.
  46. * @method delayWhen
  47. * @owner Observable
  48. */
  49. function delayWhen(delayDurationSelector, subscriptionDelay) {
  50. return operators_1.delayWhen(delayDurationSelector, subscriptionDelay)(this);
  51. }
  52. exports.delayWhen = delayWhen;
  53. //# sourceMappingURL=delayWhen.js.map