Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | import { OperatorFunction, SchedulerLike, Timestamp as TimestampInterface } 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 scheduler
|
---|
32 | * @return {Observable<Timestamp<any>>|WebSocketSubject<T>|Observable<T>}
|
---|
33 | * @method timestamp
|
---|
34 | * @owner Observable
|
---|
35 | */
|
---|
36 | export declare function timestamp<T>(scheduler?: SchedulerLike): OperatorFunction<T, Timestamp<T>>;
|
---|
37 | export declare class Timestamp<T> implements TimestampInterface<T> {
|
---|
38 | value: T;
|
---|
39 | timestamp: number;
|
---|
40 | constructor(value: T, timestamp: number);
|
---|
41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.