-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathobservable.d.ts
More file actions
113 lines (102 loc) · 3.64 KB
/
observable.d.ts
File metadata and controls
113 lines (102 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
export interface Subscriber<T = any> {
next(value: T): void;
error(error: any): void;
complete(): void;
addTeardown(teardown: () => void): void;
readonly active: boolean;
readonly signal: AbortSignal;
}
export type SubscribeCallback<T = any> = (subscriber: Subscriber<T>) => void;
export type ObservableSubscriptionCallback<T = any> = (value: T) => void;
export interface SubscriptionObserver<T = any> {
next?: ObservableSubscriptionCallback<T>;
error?: ObservableSubscriptionCallback;
complete?: () => void;
}
export type ObservableInspectorAbortHandler = (value: any) => void;
export interface ObservableInspector<T = any> {
next?: ObservableSubscriptionCallback<T>;
error?: ObservableSubscriptionCallback;
complete?: () => void;
subscribe?: () => void;
abort?: ObservableInspectorAbortHandler;
}
export type ObserverUnion<T = any> =
| ObservableSubscriptionCallback<T>
| SubscriptionObserver<T>;
export type ObservableInspectorUnion<T = any> =
| ObservableSubscriptionCallback<T>
| ObservableInspector<T>;
export interface SubscribeOptions {
signal?: AbortSignal;
}
export type TypePredicate<T = any, U extends T = T> = (
value: T,
index: number
) => value is U;
export type Predicate<T = any> = (value: T, index: number) => unknown;
export type Reducer<T = any, R = any> = (
accumulator: R,
currentValue: T,
index: number
) => R;
export type Mapper<T = any, R = any> = (value: T, index: number) => R;
export type Visitor<T = any> = (value: T, index: number) => void;
export type CatchCallback<R = any> = (value: any) => ObservableInput<R>;
export type ObservableInput<T> =
| Observable<T>
| AsyncIterable<T>
| Iterable<T>
| PromiseLike<T>;
export class Observable<T = any> {
constructor(callback: SubscribeCallback<T>);
subscribe(observer?: ObserverUnion<T>, options?: SubscribeOptions): void;
static from<T>(value: ObservableInput<T>): Observable<T>;
takeUntil(value: ObservableInput<any>): Observable<T>;
map<R>(mapper: Mapper<T, R>): Observable<R>;
filter<U extends T>(predicate: TypePredicate<T, U>): Observable<U>;
filter(predicate: Predicate<T>): Observable<T>;
take(amount: number): Observable<T>;
drop(amount: number): Observable<T>;
flatMap<R>(mapper: Mapper<T, ObservableInput<R>>): Observable<R>;
switchMap<R>(mapper: Mapper<T, ObservableInput<R>>): Observable<R>;
inspect(inspectorUnion?: ObservableInspectorUnion<T>): Observable<T>;
catch<R>(callback: CatchCallback<R>): Observable<T | R>;
finally(callback: () => void): Observable<T>;
toArray(options?: SubscribeOptions): Promise<T[]>;
forEach(callback: Visitor<T>, options?: SubscribeOptions): Promise<void>;
every(predicate: Predicate<T>, options?: SubscribeOptions): Promise<boolean>;
first(options?: SubscribeOptions): Promise<T>;
last(options?: SubscribeOptions): Promise<T>;
find<U extends T>(
predicate: TypePredicate<T, U>,
options?: SubscribeOptions
): Promise<U | undefined>;
find(
predicate: Predicate<T>,
options?: SubscribeOptions
): Promise<T | undefined>;
some(predicate: Predicate<T>, options?: SubscribeOptions): Promise<boolean>;
reduce(
reducer: Reducer<T, T>,
initialValue?: undefined,
options?: SubscribeOptions
): Promise<T | undefined>;
reduce(
reducer: Reducer<T, T>,
initialValue: T,
options?: SubscribeOptions
): Promise<T>;
reduce<R>(
reducer: Reducer<T, R>,
initialValue: R,
options?: SubscribeOptions
): Promise<R>;
}
export interface ObservableEventListenerOptions {
capture?: boolean;
passive?: boolean;
}
export declare function isSupported(): boolean;
export declare function isPolyfilled(): boolean;
export declare function apply(): void;