f0c84f3656408e92e98d1c2cb0017dc7d04c957ad2d8a2eeb7bdea48a8a2e74540a8d078bada10742eb1ef02b75a5909808a2bde8eacac6a049def2eb2d083 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { MonoTypeOperatorFunction, ObservableInput } from '../types';
  2. /**
  3. * Emits a notification from the source Observable only after a particular time span
  4. * determined by another Observable has passed without another source emission.
  5. *
  6. * <span class="informal">It's like {@link debounceTime}, but the time span of
  7. * emission silence is determined by a second Observable.</span>
  8. *
  9. * ![](debounce.svg)
  10. *
  11. * `debounce` delays notifications emitted by the source Observable, but drops previous
  12. * pending delayed emissions if a new notification arrives on the source Observable.
  13. * This operator keeps track of the most recent notification from the source
  14. * Observable, and spawns a duration Observable by calling the
  15. * `durationSelector` function. The notification is emitted only when the duration
  16. * Observable emits a next notification, and if no other notification was emitted on
  17. * the source Observable since the duration Observable was spawned. If a new
  18. * notification appears before the duration Observable emits, the previous notification will
  19. * not be emitted and a new duration is scheduled from `durationSelector` is scheduled.
  20. * If the completing event happens during the scheduled duration the last cached notification
  21. * is emitted before the completion event is forwarded to the output observable.
  22. * If the error event happens during the scheduled duration or after it only the error event is
  23. * forwarded to the output observable. The cache notification is not emitted in this case.
  24. *
  25. * Like {@link debounceTime}, this is a rate-limiting operator, and also a
  26. * delay-like operator since output emissions do not necessarily occur at the
  27. * same time as they did on the source Observable.
  28. *
  29. * ## Example
  30. *
  31. * Emit the most recent click after a burst of clicks
  32. *
  33. * ```ts
  34. * import { fromEvent, scan, debounce, interval } from 'rxjs';
  35. *
  36. * const clicks = fromEvent(document, 'click');
  37. * const result = clicks.pipe(
  38. * scan(i => ++i, 1),
  39. * debounce(i => interval(200 * i))
  40. * );
  41. * result.subscribe(x => console.log(x));
  42. * ```
  43. *
  44. * @see {@link audit}
  45. * @see {@link auditTime}
  46. * @see {@link debounceTime}
  47. * @see {@link delay}
  48. * @see {@link sample}
  49. * @see {@link sampleTime}
  50. * @see {@link throttle}
  51. * @see {@link throttleTime}
  52. *
  53. * @param durationSelector A function
  54. * that receives a value from the source Observable, for computing the timeout
  55. * duration for each source value, returned as an Observable or a Promise.
  56. * @return A function that returns an Observable that delays the emissions of
  57. * the source Observable by the specified duration Observable returned by
  58. * `durationSelector`, and may drop some values if they occur too frequently.
  59. */
  60. export declare function debounce<T>(durationSelector: (value: T) => ObservableInput<any>): MonoTypeOperatorFunction<T>;
  61. //# sourceMappingURL=debounce.d.ts.map