UNPKG

1.5 kBTypeScriptView Raw
1import { 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 *async* scheduler 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 documents click event.
16 *
17 * ```ts
18 * import { fromEvent } from 'rxjs';
19 * import { timestamp } from 'rxjs/operators';
20 *
21 * const clickWithTimestamp = fromEvent(document, 'click').pipe(
22 * timestamp()
23 * );
24 *
25 * // Emits data of type {value: MouseEvent, timestamp: number}
26 * clickWithTimestamp.subscribe(data => {
27 * console.log(data);
28 * });
29 * ```
30 *
31 * @param timestampProvider An object with a `now()` method used to get the current timestamp.
32 * @return A function that returns an Observable that attaches a timestamp to
33 * each item emitted by the source Observable indicating when it was emitted.
34 */
35export declare function timestamp<T>(timestampProvider?: TimestampProvider): OperatorFunction<T, Timestamp<T>>;
36//# sourceMappingURL=timestamp.d.ts.map
\No newline at end of file