sia-reactor 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-N5UMAYCJ.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +1 -0
- package/dist/index.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.cts +496 -9
- package/dist/utils.d.ts +496 -9
- package/dist/utils.global.js +1 -0
- package/dist/utils.js +1 -1
- package/package.json +9 -10
- package/dist/chunk-5BPIJBLB.js +0 -1
- package/dist/index-DBfVdpnb.d.cts +0 -498
- package/dist/index-DBfVdpnb.d.ts +0 -498
- package/dist/types.cjs +0 -1
- package/dist/types.d.cts +0 -24
- package/dist/types.d.ts +0 -24
- package/dist/types.js +0 -0
package/dist/utils.d.cts
CHANGED
|
@@ -1,11 +1,498 @@
|
|
|
1
|
-
|
|
2
|
-
import { CamelCase, TitleCase, NoCamelCase } from './types.cjs';
|
|
1
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
type NoTraverse =
|
|
4
|
+
| Primitive
|
|
5
|
+
| Function
|
|
6
|
+
| Date
|
|
7
|
+
| Error
|
|
8
|
+
| RegExp
|
|
9
|
+
| Promise<any>
|
|
10
|
+
| Map<any, any>
|
|
11
|
+
| WeakMap<any, any>
|
|
12
|
+
| Set<any>
|
|
13
|
+
| WeakSet<any>
|
|
14
|
+
| HTMLElement
|
|
15
|
+
| Element
|
|
16
|
+
| Node
|
|
17
|
+
| EventTarget
|
|
18
|
+
| Window
|
|
19
|
+
| Document
|
|
20
|
+
| DOMTokenList
|
|
21
|
+
| AbortSignal
|
|
22
|
+
| Inert<unknown>;
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
type Paths<T, S extends string = ".", D extends number = RDepth> = [D] extends [0]
|
|
25
|
+
? never // Circuit Breaker Triggered
|
|
26
|
+
: T extends NoTraverse
|
|
27
|
+
? never
|
|
28
|
+
: T extends readonly (infer U)[]
|
|
29
|
+
? `${Extract<keyof T, number>}` | `${Extract<keyof T, number>}${S}${Paths<U, S, RPrev[D]>}`
|
|
30
|
+
: {
|
|
31
|
+
[K in keyof T & (string | number)]: T[K] extends Primitive
|
|
32
|
+
? `${K}`
|
|
33
|
+
: `${K}` | `${K}${S}${Paths<T[K], S, RPrev[D]>}`;
|
|
34
|
+
}[keyof T & (string | number)];
|
|
35
|
+
type WildPaths<T, S extends string = "."> = "*" | Paths<T, S>;
|
|
36
|
+
type ChildPaths<T, P extends WildPaths<T>, S extends string = "."> = P extends "*"
|
|
37
|
+
? Paths<T, S>
|
|
38
|
+
: P | Extract<Paths<T, S>, `${P}${S}${string}`>;
|
|
39
|
+
|
|
40
|
+
type PathKey<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
|
|
41
|
+
? keyof T & (string | number) // Or: DeepKeys<T>
|
|
42
|
+
: PathLeaf<P, S>; // Loose since reactor just slices strings
|
|
43
|
+
type StrictPathKey<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
|
|
44
|
+
? keyof T & (string | number) // Or: DeepKeys<T>
|
|
45
|
+
: P extends `${infer K}${S}${infer Rest}`
|
|
46
|
+
? K extends keyof T
|
|
47
|
+
? StrictPathKey<T[K], Rest, S>
|
|
48
|
+
: never
|
|
49
|
+
: P extends keyof T
|
|
50
|
+
? P
|
|
51
|
+
: never; // Strict since it returns existing keys only
|
|
52
|
+
|
|
53
|
+
type PathValue<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
|
|
54
|
+
? any // Or: DeepValues<T>
|
|
55
|
+
: P extends `${infer K}${S}${infer Rest}`
|
|
56
|
+
? K extends keyof T
|
|
57
|
+
? PathValue<T[K], Rest, S>
|
|
58
|
+
: never
|
|
59
|
+
: P extends keyof T
|
|
60
|
+
? T[P]
|
|
61
|
+
: never;
|
|
62
|
+
|
|
63
|
+
type PathBranchValue<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
|
|
64
|
+
? any // Or: DeepValues<T>
|
|
65
|
+
: P extends `${string}${S}${string}`
|
|
66
|
+
? PathValue<T, PathBranch<P, S>, S>
|
|
67
|
+
: T;
|
|
68
|
+
|
|
69
|
+
type Unflatten<T extends object, S extends string = "."> = UnionToIntersection<
|
|
70
|
+
{
|
|
71
|
+
[K in keyof T & string]: UnflattenKey<K, T[K], S>;
|
|
72
|
+
}[keyof T & string]
|
|
73
|
+
>; // Turns dotted keys into nested objects while preserving value types
|
|
74
|
+
type UnflattenKey<
|
|
75
|
+
K extends string,
|
|
76
|
+
V,
|
|
77
|
+
S extends string,
|
|
78
|
+
> = K extends `${infer Head}${S}${infer Tail}`
|
|
79
|
+
? { [P in Head]: UnflattenKey<Tail, V, S> }
|
|
80
|
+
: { [P in K]: V };
|
|
81
|
+
|
|
82
|
+
// Helpers
|
|
83
|
+
type PathLeaf<
|
|
84
|
+
P extends string,
|
|
85
|
+
S extends string = ".",
|
|
86
|
+
> = P extends `${infer _Head}${S}${infer Tail}` ? PathLeaf<Tail, S> : P;
|
|
87
|
+
|
|
88
|
+
type PathBranch<
|
|
89
|
+
P extends string,
|
|
90
|
+
S extends string = ".",
|
|
91
|
+
> = P extends `${infer Head}${S}${infer Tail}`
|
|
92
|
+
? Tail extends `${string}${S}${string}`
|
|
93
|
+
? `${Head}${S}${PathBranch<Tail, S>}`
|
|
94
|
+
: Head
|
|
95
|
+
: never;
|
|
96
|
+
|
|
97
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
98
|
+
k: infer I,
|
|
99
|
+
) => void
|
|
100
|
+
? I
|
|
101
|
+
: never;
|
|
102
|
+
|
|
103
|
+
// --- "It's not that deep" WARRIORS ---
|
|
104
|
+
type DeepKeys<T, D extends number = RDepth> = [D] extends [0]
|
|
105
|
+
? never
|
|
106
|
+
: T extends NoTraverse
|
|
107
|
+
? never
|
|
108
|
+
: T extends readonly any[]
|
|
109
|
+
? DeepKeys<T[number], RPrev[D]>
|
|
110
|
+
: {
|
|
111
|
+
[K in keyof T & (string | number)]: K | DeepKeys<T[K], RPrev[D]>;
|
|
112
|
+
}[keyof T & (string | number)];
|
|
113
|
+
|
|
114
|
+
type DeepMerge<T1, T2, D extends number = RDepth> = [D] extends [0]
|
|
115
|
+
? never
|
|
116
|
+
: T2 extends object
|
|
117
|
+
? T1 extends object
|
|
118
|
+
? {
|
|
119
|
+
[K in keyof T1 | keyof T2]: K extends keyof T2
|
|
120
|
+
? K extends keyof T1
|
|
121
|
+
? DeepMerge<T1[K], T2[K], RPrev[D]>
|
|
122
|
+
: T2[K]
|
|
123
|
+
: K extends keyof T1
|
|
124
|
+
? T1[K]
|
|
125
|
+
: never;
|
|
126
|
+
}
|
|
127
|
+
: T2
|
|
128
|
+
: T2;
|
|
129
|
+
|
|
130
|
+
type DeepPartial<T, D extends number = RDepth> = [D] extends [0]
|
|
131
|
+
? never
|
|
132
|
+
: T extends Function
|
|
133
|
+
? T
|
|
134
|
+
: T extends Array<infer U>
|
|
135
|
+
? Array<DeepPartial<U, RPrev[D]>>
|
|
136
|
+
: T extends ReadonlyArray<infer U>
|
|
137
|
+
? ReadonlyArray<DeepPartial<U, RPrev[D]>>
|
|
138
|
+
: T extends object
|
|
139
|
+
? { [P in keyof T]?: DeepPartial<T[P], RPrev[D]> }
|
|
140
|
+
: T;
|
|
141
|
+
|
|
142
|
+
type DeepRequired<T, D extends number = RDepth> = [D] extends [0]
|
|
143
|
+
? never
|
|
144
|
+
: T extends Function
|
|
145
|
+
? T
|
|
146
|
+
: T extends Array<infer U>
|
|
147
|
+
? Array<DeepRequired<U, RPrev[D]>>
|
|
148
|
+
: T extends ReadonlyArray<infer U>
|
|
149
|
+
? ReadonlyArray<DeepRequired<U, RPrev[D]>>
|
|
150
|
+
: T extends object
|
|
151
|
+
? { [P in keyof T]-?: DeepRequired<T[P], RPrev[D]> }
|
|
152
|
+
: T;
|
|
153
|
+
|
|
154
|
+
// --- RECURSION LIMITERS ---
|
|
155
|
+
type RDepth = 10; // current limit for state trees, observed ts max - 19; limit needed cuz of ts bundlers
|
|
156
|
+
// This tuple maps a number to the number below it (Index 4 contains 3) allowing `RPrev[D]` to subtract 1 from our depth.
|
|
157
|
+
type RPrev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
|
|
158
|
+
|
|
159
|
+
declare const methods: readonly ["tick", "stall", "nostall", "get", "gonce", "noget", "set", "sonce", "noset", "delete", "donce", "nodelete", "watch", "wonce", "nowatch", "on", "once", "off", "cascade", "snapshot", "reset", "destroy"];
|
|
160
|
+
type Method = (typeof methods)[number];
|
|
161
|
+
type Prefix<P extends ReactivePrefs | undefined> = P extends {
|
|
162
|
+
prefix?: infer X extends string;
|
|
163
|
+
} ? X : "";
|
|
164
|
+
type Suffix<P extends ReactivePrefs | undefined> = P extends {
|
|
165
|
+
suffix?: infer X extends string;
|
|
166
|
+
} ? X : "";
|
|
167
|
+
type Whitelist<P extends ReactivePrefs | undefined> = P extends {
|
|
168
|
+
whitelist?: infer W extends readonly Method[];
|
|
169
|
+
} ? W[number] : never;
|
|
170
|
+
type ReactiveMethodMap<T extends object, P extends ReactivePrefs | undefined> = {
|
|
171
|
+
[K in Method as [Prefix<P>, Suffix<P>] extends ["", ""] ? (P extends {
|
|
172
|
+
whitelist: readonly Method[];
|
|
173
|
+
} ? (K extends Whitelist<P> ? never : K) : K) : P extends {
|
|
174
|
+
whitelist: readonly Method[];
|
|
175
|
+
} ? (K extends Whitelist<P> ? `${Prefix<P>}${K}${Suffix<P>}` : K) : `${Prefix<P>}${K}${Suffix<P>}`]: Pick<Reactor<T>, Method>[K];
|
|
176
|
+
};
|
|
177
|
+
interface ReactivePrefs {
|
|
178
|
+
prefix?: string;
|
|
179
|
+
suffix?: string;
|
|
180
|
+
whitelist?: readonly Method[];
|
|
181
|
+
}
|
|
182
|
+
type Reactive<T extends object, P extends ReactivePrefs | undefined = undefined> = T & ReactiveMethodMap<T, P> & {
|
|
183
|
+
__Reactor__: Reactor<T>;
|
|
184
|
+
};
|
|
185
|
+
declare function reactive<T extends object, const P extends ReactivePrefs | undefined = undefined>(target: T | Reactor<T>, options?: ReactorOptions<T>, prefs?: P): Reactive<T, P>;
|
|
186
|
+
declare function inert<T extends object>(target: T): Inert<T>;
|
|
187
|
+
declare function live<T extends object>(target: T): Live<T>;
|
|
188
|
+
declare function isInert<T extends object>(target: T): target is Inert<T>;
|
|
189
|
+
declare function intent<T extends object>(target: T): Intent<T>;
|
|
190
|
+
declare function state<T extends object>(target: T): State<T>;
|
|
191
|
+
declare function isIntent<T extends object>(target: T): target is Intent<T>;
|
|
192
|
+
declare function volatile<T extends object>(target: T): Volatile<T>;
|
|
193
|
+
declare function stable<T extends object>(target: T): Stable<T>;
|
|
194
|
+
declare function isVolatile<T extends object>(target: T): target is Volatile<T>;
|
|
195
|
+
declare function getVersion<T extends object>(target: T): number;
|
|
196
|
+
declare function getSnapshotVersion<T extends object>(target: T): number;
|
|
197
|
+
|
|
198
|
+
// ===========================================================================
|
|
199
|
+
// CORE MARKERS & STATE WRAPPERS
|
|
200
|
+
// ===========================================================================
|
|
201
|
+
|
|
202
|
+
type Inert<T> = T & { [INERTIA]?: true };
|
|
203
|
+
type Live<T> = T extends Inert<infer U> ? U : T;
|
|
204
|
+
|
|
205
|
+
type Intent<T> = T & { [REJECTABLE]?: true };
|
|
206
|
+
type State<T> = T extends Intent<infer U> ? U : T;
|
|
207
|
+
|
|
208
|
+
type Volatile<T> = T & { [INDIFFABLE]?: true };
|
|
209
|
+
type Stable<T> = T extends Volatile<infer U> ? U : T;
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
// ===========================================================================
|
|
213
|
+
// EVENT SYSTEM & PAYLOADS
|
|
214
|
+
// ===========================================================================
|
|
215
|
+
|
|
216
|
+
interface Target<T, P extends WildPaths<T> = WildPaths<T>> {
|
|
217
|
+
path: P;
|
|
218
|
+
value: PathValue<T, P>;
|
|
219
|
+
oldValue?: PathValue<T, P>;
|
|
220
|
+
key: PathKey<T, P>;
|
|
221
|
+
object: PathBranchValue<T, P>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Discriminated Payload Type (Creates the IDE magic)
|
|
225
|
+
type Payload<T, P extends WildPaths<T> = WildPaths<T>> =
|
|
226
|
+
| DirectPayload<T, P>
|
|
227
|
+
| UpdatePayload<T, P>;
|
|
228
|
+
|
|
229
|
+
interface BasePayload<T, P extends WildPaths<T> = WildPaths<T>> {
|
|
230
|
+
currentTarget: Target<T, P>; // use this to survive shape changes from nesting
|
|
231
|
+
root: T;
|
|
232
|
+
terminated?: boolean; // for mediators to signal operation termination but doesn't stop the chain
|
|
233
|
+
rejectable: boolean;
|
|
234
|
+
}
|
|
235
|
+
interface DirectPayload<T, P extends WildPaths<T> = WildPaths<T>> extends BasePayload<T, P> {
|
|
236
|
+
type: "init" | "get" | "set" | "delete"; // init during `immediate: true` sync
|
|
237
|
+
target: Target<T, P>;
|
|
238
|
+
}
|
|
239
|
+
interface UpdatePayload<T, P extends WildPaths<T> = WildPaths<T>> extends BasePayload<T, P> {
|
|
240
|
+
type: "update";
|
|
241
|
+
target: Target<T, ChildPaths<T, P>>; // Target is strictly one of the child paths!
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Discriminated Event Type (Creates the IDE magic)
|
|
245
|
+
type REvent<T, P extends WildPaths<T> = WildPaths<T>> =
|
|
246
|
+
| (Omit<ReactorEvent<T, P>, OverrideEvProp> &
|
|
247
|
+
DirectPayload<T, P> &
|
|
248
|
+
OverrideEvPart<DirectPayload<T, P>>)
|
|
249
|
+
| (Omit<ReactorEvent<T, P>, OverrideEvProp> &
|
|
250
|
+
UpdatePayload<T, P> &
|
|
251
|
+
OverrideEvPart<UpdatePayload<T, P>>);
|
|
252
|
+
|
|
253
|
+
type OverrideEvProp = "type" | "target" | "value" | "oldValue" | "path";
|
|
254
|
+
interface OverrideEvPart<PL extends { target: { path: any; value: any; oldValue?: any } }> {
|
|
255
|
+
path: PL["target"]["path"];
|
|
256
|
+
value: PL["target"]["value"];
|
|
257
|
+
oldValue: PL["target"]["oldValue"];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ===========================================================================
|
|
261
|
+
// REACTIVITY CALLBACKS (The Handlers)
|
|
262
|
+
// ===========================================================================
|
|
263
|
+
|
|
264
|
+
type Getter<T, P extends WildPaths<T> = WildPaths<T>> = (
|
|
265
|
+
value: PathValue<T, P>,
|
|
266
|
+
payload: Payload<T, P>,
|
|
267
|
+
) => PathValue<T, P> | undefined;
|
|
268
|
+
|
|
269
|
+
type Setter<T, P extends WildPaths<T> = WildPaths<T>> = (
|
|
270
|
+
value: PathValue<T, P>,
|
|
271
|
+
terminated: boolean,
|
|
272
|
+
payload: Payload<T, P>,
|
|
273
|
+
) => PathValue<T, P> | typeof TERMINATOR | undefined;
|
|
274
|
+
|
|
275
|
+
type Deleter<T, P extends WildPaths<T> = WildPaths<T>> = (
|
|
276
|
+
terminated: boolean,
|
|
277
|
+
payload: Payload<T, P>,
|
|
278
|
+
) => typeof TERMINATOR | undefined;
|
|
279
|
+
|
|
280
|
+
type Watcher<T, P extends WildPaths<T> = WildPaths<T>> = (
|
|
281
|
+
value: PathValue<T, P>,
|
|
282
|
+
payload: Payload<T, P>,
|
|
283
|
+
) => void;
|
|
284
|
+
|
|
285
|
+
type Listener<T, P extends WildPaths<T> = WildPaths<T>> = (event: REvent<T, P>) => void;
|
|
286
|
+
|
|
287
|
+
// ===========================================================================
|
|
288
|
+
// ENGINE RECORDS (Internal Storage)
|
|
289
|
+
// ===========================================================================
|
|
290
|
+
|
|
291
|
+
type GetterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
|
|
292
|
+
cb: Getter<T, P>;
|
|
293
|
+
clup: () => ReturnType<Reactor<T>["noget"]>;
|
|
294
|
+
sclup?: () => void;
|
|
295
|
+
} & SyncOptionsTuple;
|
|
296
|
+
|
|
297
|
+
type SetterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
|
|
298
|
+
cb: Setter<T, P>;
|
|
299
|
+
clup: () => ReturnType<Reactor<T>["noset"]>;
|
|
300
|
+
sclup?: () => void;
|
|
301
|
+
} & SyncOptionsTuple;
|
|
302
|
+
|
|
303
|
+
type DeleterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
|
|
304
|
+
cb: Deleter<T, P>;
|
|
305
|
+
clup: () => ReturnType<Reactor<T>["nodelete"]>;
|
|
306
|
+
sclup?: () => void;
|
|
307
|
+
} & SyncOptionsTuple;
|
|
308
|
+
|
|
309
|
+
type WatcherRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
|
|
310
|
+
cb: Watcher<T, P>;
|
|
311
|
+
clup: () => ReturnType<Reactor<T>["nowatch"]>;
|
|
312
|
+
sclup?: () => void;
|
|
313
|
+
} & SyncOptionsTuple;
|
|
314
|
+
|
|
315
|
+
type ListenerRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
|
|
316
|
+
cb: Listener<T, P>;
|
|
317
|
+
clup: () => ReturnType<Reactor<T>["off"]>;
|
|
318
|
+
sclup?: () => void;
|
|
319
|
+
} & ListenerOptionsTuple;
|
|
320
|
+
|
|
321
|
+
// ===========================================================================
|
|
322
|
+
// CONFIGURATION OPTIONS
|
|
323
|
+
// ===========================================================================
|
|
324
|
+
|
|
325
|
+
interface SyncOptionsTuple {
|
|
326
|
+
lazy?: boolean;
|
|
327
|
+
once?: boolean;
|
|
328
|
+
signal?: AbortSignal;
|
|
329
|
+
immediate?: boolean | "auto";
|
|
330
|
+
} // "*" path apart from listener's should not use `immediate`
|
|
331
|
+
type SyncOptions = boolean | SyncOptionsTuple;
|
|
332
|
+
|
|
333
|
+
interface ListenerOptionsTuple extends Omit<SyncOptionsTuple, "lazy"> {
|
|
334
|
+
capture?: boolean;
|
|
335
|
+
depth?: number;
|
|
336
|
+
}
|
|
337
|
+
type ListenerOptions = boolean | ListenerOptionsTuple;
|
|
338
|
+
|
|
339
|
+
// "almighty" mediation, (mediator|listener) for desired path, equality checks eg: `object.is()`
|
|
340
|
+
interface ReactorOptions<T extends object, P extends Paths<T> = Paths<T>> {
|
|
341
|
+
get?: (
|
|
342
|
+
object: PathBranchValue<T, P>,
|
|
343
|
+
key: PathKey<T, P>,
|
|
344
|
+
value: PathValue<T, P>,
|
|
345
|
+
receiver: Reactive<T>,
|
|
346
|
+
path: Paths<T> | Paths<T>[],
|
|
347
|
+
) => PathValue<T, P> | undefined;
|
|
348
|
+
set?: (
|
|
349
|
+
object: PathBranchValue<T, P>,
|
|
350
|
+
key: PathKey<T, P>,
|
|
351
|
+
value: PathValue<T, P>,
|
|
352
|
+
oldValue: PathValue<T, P>,
|
|
353
|
+
receiver: Reactive<T>,
|
|
354
|
+
path: Paths<T> | Paths<T>[],
|
|
355
|
+
) => PathValue<T, P> | typeof TERMINATOR | undefined;
|
|
356
|
+
delete?: (
|
|
357
|
+
object: PathBranchValue<T, P>,
|
|
358
|
+
key: PathKey<T, P>,
|
|
359
|
+
oldValue: PathValue<T, P>,
|
|
360
|
+
receiver: Reactive<T>,
|
|
361
|
+
path: Paths<T> | Paths<T>[],
|
|
362
|
+
) => typeof TERMINATOR | undefined;
|
|
363
|
+
debug?: boolean;
|
|
364
|
+
crossRealms?: boolean; // needed for object type detection if using across realms e.g, iframes or other environments
|
|
365
|
+
smartCloning?: boolean; // one-time set for structural sharing, needs `.referenceTracking: true`
|
|
366
|
+
eventBubbling?: boolean; // default true, set to false to prevent bubbling (not recommended if you want power)
|
|
367
|
+
lineageTracing?: boolean; // one-time set for tree walking to search for refs on property access, needs `.referenceTracking = true`
|
|
368
|
+
batchingFunction?: (cb: () => void) => void; // one-time set for listener's notifications, e.g: `queueMicrotask`, `unstable_batchedUpdates` from ReactDOM
|
|
369
|
+
referenceTracking?: boolean; // one-time set to activate
|
|
370
|
+
} // debating making use of the Reflect API opt-in
|
|
371
|
+
|
|
372
|
+
declare function isDef(val: any): boolean;
|
|
373
|
+
declare function isArr<T = unknown>(obj: any): obj is T[];
|
|
374
|
+
declare function isObj<T extends object = object>(obj: any, checkArr?: boolean): obj is T;
|
|
375
|
+
declare function isStrictObj<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
|
|
376
|
+
declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
|
|
377
|
+
declare function inBoolArrOpt(opt: any, str: string): boolean;
|
|
378
|
+
declare function setAny<T extends object, const S extends string = ".">(target: T, key: Paths<T, S>, value: PathValue<T, typeof key, S>, separator?: S, keyFunc?: (p: string) => string): void;
|
|
379
|
+
declare function getAny<T extends object, const S extends string = ".">(source: T, key: Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): PathValue<T, typeof key, S> | undefined;
|
|
380
|
+
declare function deleteAny<T extends object, const S extends string = ".">(target: T, key: Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): void;
|
|
381
|
+
declare function inAny<T extends object, const S extends string = ".">(source: T, key: string | Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): boolean;
|
|
382
|
+
declare function parseAnyObj<T extends Record<string, any>, const S extends string = ".">(obj: T, separator?: S, keyFunc?: (p: string) => string, visited?: WeakSet<WeakKey>): Unflatten<T, S>;
|
|
383
|
+
declare function parseEvOpts<T extends object>(options: T | boolean | undefined, opts: (keyof T)[] | readonly (keyof T)[], boolOpt?: keyof T, result?: T): T;
|
|
384
|
+
declare function mergeObjs<T1 extends object, T2 extends object>(o1: T1, o2: T2): DeepMerge<T1, T2>;
|
|
385
|
+
declare function mergeObjs<T1 extends object>(o1: T1): T1;
|
|
386
|
+
declare function mergeObjs<T2 extends object>(o1: undefined | null, o2: T2): T2;
|
|
387
|
+
declare function getTrailPaths<T>(path: WildPaths<T>, reverse?: boolean): WildPaths<T>[];
|
|
388
|
+
declare function getTrailRecords<T extends object>(obj: T, path: WildPaths<T>): [WildPaths<T>, PathValue<T, WildPaths<T>>, PathValue<T, WildPaths<T>>][];
|
|
389
|
+
declare function deepClone<T>(obj: T, crossRealms?: boolean, visited?: WeakMap<WeakKey, any>): T;
|
|
390
|
+
declare function nuke(target: any): void;
|
|
391
|
+
|
|
392
|
+
declare const INERTIA: unique symbol;
|
|
393
|
+
declare const REJECTABLE: unique symbol;
|
|
394
|
+
declare const INDIFFABLE: unique symbol;
|
|
395
|
+
declare const TERMINATOR: unique symbol;
|
|
396
|
+
declare class ReactorEvent<T, P extends WildPaths<T> = WildPaths<T>> {
|
|
397
|
+
static readonly NONE = 0;
|
|
398
|
+
static readonly CAPTURING_PHASE = 1;
|
|
399
|
+
static readonly AT_TARGET = 2;
|
|
400
|
+
static readonly BUBBLING_PHASE = 3;
|
|
401
|
+
eventPhase: number;
|
|
402
|
+
type: Payload<T, P>["type"];
|
|
403
|
+
currentTarget: Payload<T, P>["currentTarget"];
|
|
404
|
+
readonly staticType: Payload<T, P>["type"];
|
|
405
|
+
readonly target: Payload<T, P>["target"];
|
|
406
|
+
readonly root: Payload<T, P>["root"];
|
|
407
|
+
readonly path: Payload<T, P>["target"]["path"];
|
|
408
|
+
readonly value: Payload<T, P>["target"]["value"];
|
|
409
|
+
readonly oldValue: Payload<T, P>["target"]["oldValue"];
|
|
410
|
+
readonly rejectable: boolean;
|
|
411
|
+
readonly bubbles: boolean;
|
|
412
|
+
protected _propagationStopped: boolean;
|
|
413
|
+
protected _immediatePropagationStopped: boolean;
|
|
414
|
+
protected _resolved: string;
|
|
415
|
+
protected _rejected: string;
|
|
416
|
+
protected _warn: (...args: any[]) => void;
|
|
417
|
+
constructor(payload: Payload<T, P>, bubbles?: boolean, canWarn?: boolean);
|
|
418
|
+
get propagationStopped(): boolean;
|
|
419
|
+
stopPropagation(): void;
|
|
420
|
+
get immediatePropagationStopped(): boolean;
|
|
421
|
+
stopImmediatePropagation(): void;
|
|
422
|
+
get resolved(): string;
|
|
423
|
+
resolve(message?: string): void;
|
|
424
|
+
get rejected(): string;
|
|
425
|
+
reject(reason?: string): void;
|
|
426
|
+
composedPath(): WildPaths<T>[];
|
|
427
|
+
get canWarn(): boolean;
|
|
428
|
+
}
|
|
429
|
+
declare class Reactor<T extends object> {
|
|
430
|
+
protected getters?: Map<WildPaths<T>, Array<GetterRecord<T>>>;
|
|
431
|
+
protected setters?: Map<WildPaths<T>, Array<SetterRecord<T>>>;
|
|
432
|
+
protected deleters?: Map<WildPaths<T>, Array<DeleterRecord<T>>>;
|
|
433
|
+
protected watchers?: Map<WildPaths<T>, Array<WatcherRecord<T>>>;
|
|
434
|
+
protected listeners?: Map<WildPaths<T>, Array<ListenerRecord<T>>>;
|
|
435
|
+
protected lineage?: WeakMap<object, (object | string)[]>;
|
|
436
|
+
protected queue?: Set<() => void>;
|
|
437
|
+
protected batch?: Map<Paths<T>, Payload<T>>;
|
|
438
|
+
protected proxyCache: WeakMap<object, any>;
|
|
439
|
+
protected snapshotCache?: WeakMap<object, any>;
|
|
440
|
+
protected log: (...args: any[]) => void;
|
|
441
|
+
config: Omit<ReactorOptions<T>, "debug" | "referenceTracking" | "lineageTracing" | "smartCloning">;
|
|
442
|
+
core: T;
|
|
443
|
+
protected isLogging: boolean;
|
|
444
|
+
protected isTracing: boolean;
|
|
445
|
+
protected isTracking: boolean;
|
|
446
|
+
protected isSCloning: boolean;
|
|
447
|
+
protected isBatching: boolean;
|
|
448
|
+
constructor(obj?: T, options?: ReactorOptions<T>);
|
|
449
|
+
protected proxied<O extends object>(obj: O, rejectable?: boolean, indiffable?: boolean, parent?: object, key?: string, path?: string): O;
|
|
450
|
+
protected trace(target: object, path: string, paths?: string[], visited?: WeakSet<object>): Paths<T>[];
|
|
451
|
+
protected link(target: any, parent: object, key: string, typecheck?: boolean, es?: (object | string)[]): void;
|
|
452
|
+
protected unlink(target: any, parent: object, key: string): void;
|
|
453
|
+
protected stamp(target: any, typecheck?: boolean): void;
|
|
454
|
+
protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "get", cords: GetterRecord<T>[]): PathValue<T, P>;
|
|
455
|
+
protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "set", cords: SetterRecord<T>[]): PathValue<T, P>;
|
|
456
|
+
protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "delete", cords: DeleterRecord<T>[]): PathValue<T, P>;
|
|
457
|
+
protected notify<P extends Paths<T>>(path: P, payload: Payload<T, P>): void;
|
|
458
|
+
protected schedule<P extends Paths<T>>(path: P, payload: Payload<T, P>): void;
|
|
459
|
+
protected initBatching(): void;
|
|
460
|
+
protected flush(): void;
|
|
461
|
+
protected wave(path: Paths<T>, payload: Payload<T>): void;
|
|
462
|
+
protected fire([path, object, value]: ReturnType<typeof getTrailRecords<T>>[number], e: REvent<T>, isCapture: boolean, cords?: ListenerRecord<T>[] | undefined): void;
|
|
463
|
+
tick(paths?: Paths<T> | Iterable<Paths<T>>): void;
|
|
464
|
+
stall(task: () => any): void;
|
|
465
|
+
nostall(task: () => any): boolean | undefined;
|
|
466
|
+
protected bind<Cb>(cord: GetterRecord<T> | SetterRecord<T> | DeleterRecord<T> | WatcherRecord<T> | ListenerRecord<T>, signal?: AbortSignal): Cb;
|
|
467
|
+
protected clone(obj: any, raw: boolean, visited?: WeakMap<WeakKey, any>): any;
|
|
468
|
+
getDepth(p: string, d?: number): number;
|
|
469
|
+
protected getContext<P extends WildPaths<T>>(path: P): Target<T, P>;
|
|
470
|
+
protected syncAdd<P extends WildPaths<T>>(key: "get" | "set" | "delete" | "watch", path: P, cb: any, opts: SyncOptions | undefined, onImmediate?: (immediate: boolean | "auto") => void): () => boolean | undefined;
|
|
471
|
+
protected syncDrop<P extends WildPaths<T>>(store: Map<WildPaths<T>, any[]> | undefined, path: P, cb: any): boolean | undefined;
|
|
472
|
+
get<P extends WildPaths<T>>(path: P, cb: Getter<T, P>, opts?: SyncOptions): Reactor<T>["noget"];
|
|
473
|
+
gonce<P extends WildPaths<T>>(path: P, cb: Getter<T, P>, opts?: SyncOptions): Reactor<T>["noget"];
|
|
474
|
+
noget<P extends WildPaths<T>>(path: P, cb: Getter<T, P>): boolean | undefined;
|
|
475
|
+
set<P extends WildPaths<T>>(path: P, cb: Setter<T, P>, opts?: SyncOptions): Reactor<T>["noset"];
|
|
476
|
+
sonce<P extends WildPaths<T>>(path: P, cb: Setter<T, P>, opts?: SyncOptions): Reactor<T>["noset"];
|
|
477
|
+
noset<P extends WildPaths<T>>(path: P, cb: Setter<T, P>): boolean | undefined;
|
|
478
|
+
delete<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>, opts?: SyncOptions): Reactor<T>["nodelete"];
|
|
479
|
+
donce<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>, opts?: SyncOptions): Reactor<T>["nodelete"];
|
|
480
|
+
nodelete<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>): boolean | undefined;
|
|
481
|
+
watch<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>, opts?: SyncOptions): Reactor<T>["nowatch"];
|
|
482
|
+
wonce<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>, opts?: SyncOptions): Reactor<T>["nowatch"];
|
|
483
|
+
nowatch<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>): boolean | undefined;
|
|
484
|
+
on<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): Reactor<T>["off"];
|
|
485
|
+
once<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): Reactor<T>["off"];
|
|
486
|
+
off<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): boolean | undefined;
|
|
487
|
+
snapshot(raw?: boolean, branch?: T): T;
|
|
488
|
+
cascade({ type, currentTarget: { path, value: news, oldValue: olds } }: ReactorEvent<T>, objSafe?: boolean): void;
|
|
489
|
+
reset(): void;
|
|
490
|
+
destroy(): void;
|
|
491
|
+
get canLog(): boolean;
|
|
492
|
+
set canLog(value: boolean);
|
|
493
|
+
get canTrackReferences(): boolean;
|
|
494
|
+
get canTraceLineage(): boolean;
|
|
495
|
+
get canSmartClone(): boolean;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export { live as $, type StrictPathKey as A, type SyncOptions as B, type ChildPaths as C, type DeepKeys as D, type SyncOptionsTuple as E, type Target as F, type Getter as G, type UnionToIntersection as H, type Inert as I, type UpdatePayload as J, type WatcherRecord as K, type Listener as L, type WildPaths as M, getSnapshotVersion as N, getVersion as O, type PathBranch as P, inert as Q, type REvent as R, type Setter as S, TERMINATOR as T, type Unflatten as U, type Volatile as V, type Watcher as W, intent as X, isInert as Y, isIntent as Z, isVolatile as _, type DeepMerge as a, methods as a0, reactive as a1, stable as a2, state as a3, volatile as a4, type DeepPartial as b, type DeepRequired as c, type Deleter as d, deepClone, deleteAny, type DeleterRecord as e, type DirectPayload as f, type GetterRecord as g, getAny, getTrailPaths, getTrailRecords, type Intent as h, type ListenerOptions as i, inAny, inBoolArrOpt, isArr, isDef, isIter, isObj, isStrictObj, type ListenerOptionsTuple as j, type ListenerRecord as k, type Live as l, type PathBranchValue as m, mergeObjs, type PathKey as n, nuke, type PathLeaf as o, type PathValue as p, parseAnyObj, parseEvOpts, type Paths as q, type Payload as r, type Reactive as s, setAny, type ReactivePrefs as t, Reactor as u, ReactorEvent as v, type ReactorOptions as w, type SetterRecord as x, type Stable as y, type State as z };
|