-
Notifications
You must be signed in to change notification settings - Fork 2
/
types.ts
31 lines (27 loc) · 986 Bytes
/
types.ts
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
export type Listener<T> = (val: T) => void
export type Cleanup = () => void
export type Producer<T> = (
listener: Listener<T>,
finalize: (cleanup: Cleanup) => void
) => Cleanup | void | Promise<void>
export interface SourceLike<T> {
get(listener?: Listener<T>): T | undefined
remove(listener: Listener<T>): void
stop(): void
stops(): Promise<void>
stopped: boolean
}
export function isSourceLike<T>(val: any): val is SourceLike<T> {
return val &&
typeof val.get === 'function' &&
typeof val.remove === 'function' &&
typeof val.stop === 'function' &&
typeof val.stops === 'function'
}
export const SKIP = Symbol()
export const STOP = Symbol()
export type ExprResultSync<T> = T | typeof SKIP | typeof STOP
export type ExprResult<T> = ExprResultSync<T> | Promise<ExprResultSync<T>>
export type Track = <T>(obs: Observable<T>) => T | undefined
export type ExprFn<T> = (track: Track) => ExprResult<T>
export type Observable<T> = SourceLike<T> | ExprFn<T>