157abbd4fb074f900ad2ccecc1899ef601486288149e01830a137be16047728b2b750a7a1fffe5d955b794a57ced3636d14573df759c758c98849973ad22e1 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { OperatorFunction, TimestampProvider, Timestamp } from '../types';
  2. /**
  3. * Attaches a timestamp to each item emitted by an observable indicating when it was emitted
  4. *
  5. * The `timestamp` operator maps the *source* observable stream to an object of type
  6. * `{value: T, timestamp: R}`. The properties are generically typed. The `value` property contains the value
  7. * and type of the *source* observable. The `timestamp` is generated by the schedulers `now` function. By
  8. * default, it uses the `asyncScheduler` which simply returns `Date.now()` (milliseconds since 1970/01/01
  9. * 00:00:00:000) and therefore is of type `number`.
  10. *
  11. * ![](timestamp.png)
  12. *
  13. * ## Example
  14. *
  15. * In this example there is a timestamp attached to the document's click events
  16. *
  17. * ```ts
  18. * import { fromEvent, timestamp } from 'rxjs';
  19. *
  20. * const clickWithTimestamp = fromEvent(document, 'click').pipe(
  21. * timestamp()
  22. * );
  23. *
  24. * // Emits data of type { value: PointerEvent, timestamp: number }
  25. * clickWithTimestamp.subscribe(data => {
  26. * console.log(data);
  27. * });
  28. * ```
  29. *
  30. * @param timestampProvider An object with a `now()` method used to get the current timestamp.
  31. * @return A function that returns an Observable that attaches a timestamp to
  32. * each item emitted by the source Observable indicating when it was emitted.
  33. */
  34. export declare function timestamp<T>(timestampProvider?: TimestampProvider): OperatorFunction<T, Timestamp<T>>;
  35. //# sourceMappingURL=timestamp.d.ts.map