Front end of the Slack clone application.

delayWhen.d.ts 2.4KB

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