wishthis/node_modules/rxjs/internal/operators/timestamp.d.ts

42 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-05-29 09:24:36 +00:00
import { OperatorFunction, SchedulerLike, Timestamp as TimestampInterface } from '../types';
2022-01-21 08:28:41 +00:00
/**
* Attaches a timestamp to each item emitted by an observable indicating when it was emitted
*
* The `timestamp` operator maps the *source* observable stream to an object of type
* `{value: T, timestamp: R}`. The properties are generically typed. The `value` property contains the value
* and type of the *source* observable. The `timestamp` is generated by the schedulers `now` function. By
2022-05-29 09:24:36 +00:00
* default it uses the *async* scheduler which simply returns `Date.now()` (milliseconds since 1970/01/01
2022-01-21 08:28:41 +00:00
* 00:00:00:000) and therefore is of type `number`.
*
* ![](timestamp.png)
*
* ## Example
*
2022-05-29 09:24:36 +00:00
* In this example there is a timestamp attached to the documents click event.
2022-01-21 08:28:41 +00:00
*
* ```ts
2022-05-29 09:24:36 +00:00
* import { fromEvent } from 'rxjs';
* import { timestamp } from 'rxjs/operators';
2022-01-21 08:28:41 +00:00
*
* const clickWithTimestamp = fromEvent(document, 'click').pipe(
* timestamp()
* );
*
2022-05-29 09:24:36 +00:00
* // Emits data of type {value: MouseEvent, timestamp: number}
2022-01-21 08:28:41 +00:00
* clickWithTimestamp.subscribe(data => {
* console.log(data);
* });
* ```
*
2022-05-29 09:24:36 +00:00
* @param scheduler
* @return {Observable<Timestamp<any>>|WebSocketSubject<T>|Observable<T>}
* @method timestamp
* @owner Observable
2022-01-21 08:28:41 +00:00
*/
2022-05-29 09:24:36 +00:00
export declare function timestamp<T>(scheduler?: SchedulerLike): OperatorFunction<T, Timestamp<T>>;
export declare class Timestamp<T> implements TimestampInterface<T> {
value: T;
timestamp: number;
constructor(value: T, timestamp: number);
}