-
Notifications
You must be signed in to change notification settings - Fork 17
/
types.ts
71 lines (61 loc) · 1.87 KB
/
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
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
import { Hex } from './utils'
export type Scope = string
export interface ScopeModel {
[key: string]: ContainerRef
}
export type InstanceId = Hex | string
export type Resolver = <T>(id: InstanceId, value?: T) => T | void
export type Rejector = <T>(id: InstanceId, reason?: T) => T | void
export type InstanceComponent<T> = React.ComponentType<T>
export interface InstanceOptions {
scope?: Scope
instanceId?: InstanceId
enterTimeout?: number
exitTimeout?: number
}
export interface InstanceProps<Result> extends InstanceOptions {
isOpen: boolean
instanceId: Hex
onReject: (reason?: Result) => void
onResolve: (result?: Result) => void
/** @deprecated **/
open: boolean
/** @deprecated **/
close: (result?: Result) => void
}
export interface Instance extends InstanceOptions {
Component: InstanceComponent<any>
props: InstanceOptions
resolve: (value?: any) => void
reject: (reason?: any) => void
}
export interface ContainerProps extends InstanceOptions {
isAppendIntances?: boolean
onOpen?: (id?: InstanceId, instance?: Instance) => void
onResolve?: Resolver
onReject?: Rejector
onRemove?: (id?: InstanceId) => void
}
export interface ContainerRef {
create: InstanceCreator
resolve: Resolver
resolveAll: <T>(value?: T) => void
reject: Rejector
rejectAll: <T>(reason?: T) => void
getInstance: (id: InstanceId) => Instance | null
hasInstance: (id: InstanceId) => boolean
}
export interface CreateInstance {
<T extends InstanceProps<Result>, Result = any>(
Component: InstanceComponent<T>,
options?: InstanceOptions
): (
props?: Omit<T, keyof InstanceProps<Result>> &
Partial<InstanceProps<Result>>
) => Promise<Result>
}
export type InstanceCreator = <T, Result>(
Component: InstanceComponent<T>,
options?: InstanceOptions,
props?: Omit<T, keyof InstanceProps<Result>> & Partial<InstanceProps<Result>>
) => Promise<Result>