-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactive.d.ts
208 lines (181 loc) · 4.76 KB
/
reactive.d.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
interface Reactive {
<T>(target: T): T
}
type Track = (target: any, key: string | Symbol) => void
declare const TRIGGER_TYPE: {
readonly ADD: 'TRIGGER_TYPE.ADD'
readonly SET: 'TRIGGER_TYPE.SET'
readonly DELETE: 'TRIGGER_TYPE.DELETE'
readonly CLEAR: 'TRIGGER_TYPE.CLEAR'
readonly EmptySlotSet: 'TRIGGER_TYPE.EmptySlotSet'
readonly LengthSubtract: 'TRIGGER_TYPE.LengthSubtract'
}
type TRIGGER_TYPE_TD = typeof TRIGGER_TYPE
type TriggerType = TRIGGER_TYPE_TD[keyof TRIGGER_TYPE_TD]
type Trigger = (
target: any,
key: string,
type: TriggerType,
newVal: any,
isArrayProperty: boolean
) => void
declare const TRY_PROXY_NO_RESULT: 'TRY_PROXY_NO_RESULT'
interface ReactiveCtor {
trySet<T>(
target: T,
key: any,
newVal: any,
receiver: T
): false | typeof TRY_PROXY_NO_RESULT
/**@deprecated */
handleSetFail<T>(
target: T,
key: any,
newVal: any,
receiver: T,
suc?: boolean
): boolean
handleArray(
target: Array<any>,
key: string | symbol,
receiver: Array<any>
): ((...args: any[]) => any) | typeof TRY_PROXY_NO_RESULT | any
tryGetFlag<T>(
target: T,
key: any,
receiver: T
): T | boolean | typeof TRY_PROXY_NO_RESULT
tryGet<T>(
target: T,
key: any,
receiver: T,
isSetOrMap?: boolean
):
| T
| boolean
| number
| ((...args: any[]) => any)
| typeof TRY_PROXY_NO_RESULT
| never
| any
tryGetForSetOrMap<T>(
target: T,
key: any,
receiver: T
): (...args: any[]) => any | number | never
}
interface ProxyTrapOption {
version?: string
Effect: EffectM
Reactive: ReactiveCtor
isShallow: boolean
isReadonly: boolean
readonly: Reactive
reactive: Reactive
track: Track
trigger: Trigger
reactiveInfo: WeakMap<object, object>
}
type SetProto = SetConstructor['prototype']
type SetProtoKeys = 'add' | 'delete' | 'has' | 'clear'
type WsProto = WeakSetConstructor['prototype']
type MapProto = MapConstructor['prototype']
type WmProto = WeakMapConstructor['prototype']
type SetMap = SetConstructor | MapConstructor
type SetMapPrototype = SetMap['prototype']
type MapWm = MapConstructor | WeakMapConstructor
type MapWmPrototype = MapWm['prototype']
type SetWs = SetConstructor | WeakSetConstructor
type SetWsPrototype = SetWs['prototype']
type WeakSetMap = WeakSetConstructor | WeakMapConstructor
type WeakSetMapPrototype = WeakSetMap['prototype']
type SetMapWsWm =
| SetConstructor
| MapConstructor
| WeakSetConstructor
| WeakMapConstructor
type SetMapWsWmPrototype = SetMapWsWm['prototype']
type ProxyTrapOptionKey = keyof ProxyTrapOption
interface WithRecordTrapOption {
<F>(e: {
factory: (option?: ProxyTrapOption) => F
factoryName: string
version: string
option?: ProxyTrapOption
getDiff?: GetDiff<ProxyTrapOption>
isShallow: boolean
isReadonly: boolean
isSetOrMap?: boolean
}): F
}
type GetTrap = ProxyHandler<any>['get'] & {
trapForSetAndMap?: ProxyHandler<any>['get']
}
type ProxyHandlerKeyNoGet =
| 'set'
| 'deleteProperty'
| 'has'
| 'ownKeys'
| 'getOwnPropertyDescriptor'
| 'defineProperty'
| 'apply'
type ProxyHandlerKey = 'get' | ProxyHandlerKeyNoGet
interface TrapInnerFactory {
(
isShallow: boolean,
isReadonly: boolean,
options: ProxyTrapOption
): (...args: any[]) => any
}
interface ReactiveCtorFactory {
// (
// isShallow: boolean,
// isReadonly: boolean,
// options: ProxyTrapOption
// ): ReactiveCtor
(
options: ProxyTrapOption & {
ReactiveBase: ReactiveCtor
arrayInstrumentations?: any[]
setMapInstrumentations?: WeakMap<object, SetMapWsWmPrototype>
}
): ReactiveCtor
}
interface ArrayProtoProxyFactory {
(
options: {
isShallow: boolean
isReadonly: boolean
applyWithoutEffect?: EffectM['applyWithoutEffect']
finds?: ArrayConstructor['prototype']
stacks?: ArrayConstructor['prototype']
} & ProxyTrapOption
): ArrayConstructor['prototype']
}
type Trap<K extends ProxyHandlerKey> = (Omit<ProxyHandler<any>, 'get'> & {
get: GetTrap
})[K]
interface TrapFactory<K extends ProxyHandlerKey> {
// (isShallow: boolean, isReadonly: boolean, options: ProxyTrapOption): Trap<K>
(options: ProxyTrapOption): Trap<K>
}
interface TrapGetter<K extends ProxyHandlerKey> {
(options: ProxyTrapOption): Trap<K>
}
interface CreateReactive {
(
isShallow?: boolean,
isReadonly?: boolean,
version?: string
): {
(callFromSelfTrap?: boolean): Reactive
trapGetters?: TrapGetter<any>
trapOption?: ProxyTrapOption
reactiveInfo?: ProxyTrapOption['reactiveInfo']
getProxyHandler?(target?: object): ProxyHandler<object>
}
}
type ReactiveApiCreator = ReturnType<CreateReactive>
type PH = ProxyHandler<any>
type ProxyTrap = PH[keyof PH]
type ProxyTrapGetter = (opt: ProxyTrapOption) => ProxyTrap