@but212/atom-effect 0.26.0 → 0.28.0
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/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +69 -10
- package/dist/index.mjs +631 -453
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -27,9 +27,21 @@ export declare function atom<T>(initialValue: T, options?: AtomOptions): Writabl
|
|
|
27
27
|
export declare class AtomError extends Error {
|
|
28
28
|
cause: Error | null;
|
|
29
29
|
recoverable: boolean;
|
|
30
|
+
name: string;
|
|
30
31
|
constructor(message: string, cause?: Error | null, recoverable?: boolean);
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Creates a two-way "lens" for a specific property path on an object-based atom.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const store = atom({ user: { name: 'Alice' } });
|
|
39
|
+
* const nameLens = atomLens(store, 'user.name');
|
|
40
|
+
* console.log(nameLens.value); // 'Alice'
|
|
41
|
+
* nameLens.value = 'Bob'; // Updates store.user.name immutably
|
|
42
|
+
*/
|
|
43
|
+
export declare function atomLens<T extends object, P extends Paths<T>>(atom: WritableAtom<T>, path: P): WritableAtom<PathValue<T, P>>;
|
|
44
|
+
|
|
33
45
|
/**
|
|
34
46
|
* Atom options.
|
|
35
47
|
*/
|
|
@@ -46,6 +58,11 @@ export declare interface AtomOptions {
|
|
|
46
58
|
*/
|
|
47
59
|
export declare function batch<T>(fn: () => T): T;
|
|
48
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Composes an existing lens with a sub-path to create a deeper lens.
|
|
63
|
+
*/
|
|
64
|
+
export declare const composeLens: <T extends object, P extends Paths<T>>(lens: WritableAtom<T>, path: P) => WritableAtom<PathValue<T, P>>;
|
|
65
|
+
|
|
49
66
|
/**
|
|
50
67
|
* Creates a computed value.
|
|
51
68
|
* @param fn - Computation function
|
|
@@ -76,6 +93,7 @@ export declare interface ComputedAtom<T = unknown> extends ReadonlyAtom<T>, Disp
|
|
|
76
93
|
|
|
77
94
|
/** Computed error. */
|
|
78
95
|
export declare class ComputedError extends AtomError {
|
|
96
|
+
name: string;
|
|
79
97
|
constructor(message: string, cause?: Error | null);
|
|
80
98
|
}
|
|
81
99
|
|
|
@@ -104,7 +122,7 @@ export declare const DEBUG_CONFIG: {
|
|
|
104
122
|
};
|
|
105
123
|
|
|
106
124
|
/**
|
|
107
|
-
*
|
|
125
|
+
* Global debug controller singleton.
|
|
108
126
|
*/
|
|
109
127
|
export declare const DEBUG_RUNTIME: DebugConfig;
|
|
110
128
|
|
|
@@ -129,6 +147,8 @@ export declare interface Dependency {
|
|
|
129
147
|
/* Excluded from this release type: version */
|
|
130
148
|
/* Excluded from this release type: flags */
|
|
131
149
|
/* Excluded from this release type: _lastSeenEpoch */
|
|
150
|
+
/* Excluded from this release type: isComputed */
|
|
151
|
+
/* Excluded from this release type: hasError */
|
|
132
152
|
/**
|
|
133
153
|
* Adds a subscriber to this dependency.
|
|
134
154
|
* The listener may optionally receive the new and previous values.
|
|
@@ -157,6 +177,7 @@ export declare function effect(fn: EffectFunction, options?: EffectOptions): Eff
|
|
|
157
177
|
|
|
158
178
|
/** Effect error. */
|
|
159
179
|
export declare class EffectError extends AtomError {
|
|
180
|
+
name: string;
|
|
160
181
|
constructor(message: string, cause?: Error | null);
|
|
161
182
|
}
|
|
162
183
|
|
|
@@ -181,6 +202,11 @@ export declare interface EffectOptions {
|
|
|
181
202
|
onError?: (error: unknown) => void;
|
|
182
203
|
}
|
|
183
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Helper to retrieve a nested value from an object/array at a given path.
|
|
207
|
+
*/
|
|
208
|
+
export declare function getPathValue(source: unknown, parts: string[]): unknown;
|
|
209
|
+
|
|
184
210
|
/**
|
|
185
211
|
* Readonly atom check.
|
|
186
212
|
*
|
|
@@ -198,6 +224,36 @@ export declare function isComputed(obj: unknown): obj is ComputedAtom;
|
|
|
198
224
|
*/
|
|
199
225
|
export declare function isEffect(obj: unknown): obj is EffectObject;
|
|
200
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Creates a lens factory bound to a specific atom.
|
|
229
|
+
*/
|
|
230
|
+
export declare const lensFor: <T extends object>(atom: WritableAtom<T>) => <P extends Paths<T>>(path: P) => WritableAtom<PathValue<T, P>>;
|
|
231
|
+
|
|
232
|
+
/** Max recursion depth for dot-paths. */
|
|
233
|
+
export declare type MaxDepth = 8;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Generates a union of all possible dot-separated paths for a given type T.
|
|
237
|
+
*
|
|
238
|
+
* Used for `atomLens` to provide IDE autocomplete and type safety when
|
|
239
|
+
* zooming into deeply nested reactive objects.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* type User = { profile: { name: string } };
|
|
243
|
+
* type P = Paths<User>; // "profile" | "profile.name"
|
|
244
|
+
*/
|
|
245
|
+
export declare type Paths<T, D extends unknown[] = []> = D['length'] extends MaxDepth ? never : T extends object ? {
|
|
246
|
+
[K in keyof T & (string | number)]-?: `${K}` | (T[K] extends object ? `${K}.${Paths<T[K], [...D, 1]>}` : never);
|
|
247
|
+
}[keyof T & (string | number)] : never;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Resolves the type of a value at a specific dot-path P within type T.
|
|
251
|
+
*
|
|
252
|
+
* Works in tandem with `Paths<T>` to ensure that lensed atoms have
|
|
253
|
+
* the correct inferred type for the member they point to.
|
|
254
|
+
*/
|
|
255
|
+
export declare type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? StringKeyToNumber<K> extends keyof T ? PathValue<T[StringKeyToNumber<K> & keyof T], Rest> : never : StringKeyToNumber<P> extends keyof T ? T[StringKeyToNumber<P> & keyof T] : never;
|
|
256
|
+
|
|
201
257
|
export declare interface PoolStats {
|
|
202
258
|
acquired: number;
|
|
203
259
|
released: number;
|
|
@@ -235,7 +291,7 @@ export declare interface ReadonlyAtom<T = unknown> {
|
|
|
235
291
|
/**
|
|
236
292
|
* Scheduler implementation.
|
|
237
293
|
*/
|
|
238
|
-
declare class
|
|
294
|
+
declare class Scheduler_2 {
|
|
239
295
|
/** Queue buffer */
|
|
240
296
|
_queueBuffer: [SchedulerJob[], SchedulerJob[]];
|
|
241
297
|
_bufferIndex: number;
|
|
@@ -244,7 +300,6 @@ declare class Scheduler {
|
|
|
244
300
|
_epoch: number;
|
|
245
301
|
/** State flags */
|
|
246
302
|
_isProcessing: boolean;
|
|
247
|
-
_isBatching: boolean;
|
|
248
303
|
_isFlushingSync: boolean;
|
|
249
304
|
/** Batching state */
|
|
250
305
|
_batchDepth: number;
|
|
@@ -256,7 +311,6 @@ declare class Scheduler {
|
|
|
256
311
|
onOverflow: ((droppedCount: number) => void) | null;
|
|
257
312
|
/** Bound run loop for microtask */
|
|
258
313
|
private readonly _boundRunLoop;
|
|
259
|
-
get phase(): SchedulerPhase;
|
|
260
314
|
get queueSize(): number;
|
|
261
315
|
get isBatching(): boolean;
|
|
262
316
|
/**
|
|
@@ -281,7 +335,8 @@ declare class Scheduler {
|
|
|
281
335
|
setMaxFlushIterations(max: number): void;
|
|
282
336
|
}
|
|
283
337
|
|
|
284
|
-
|
|
338
|
+
declare const scheduler_2: Scheduler_2;
|
|
339
|
+
export { scheduler_2 as scheduler }
|
|
285
340
|
|
|
286
341
|
/**
|
|
287
342
|
* Scheduler configuration.
|
|
@@ -297,6 +352,7 @@ export declare const SCHEDULER_CONFIG: {
|
|
|
297
352
|
|
|
298
353
|
/** Scheduler error. */
|
|
299
354
|
export declare class SchedulerError extends AtomError {
|
|
355
|
+
name: string;
|
|
300
356
|
constructor(message: string, cause?: Error | null);
|
|
301
357
|
}
|
|
302
358
|
|
|
@@ -314,11 +370,14 @@ declare interface SchedulerJobObject {
|
|
|
314
370
|
_nextEpoch?: number;
|
|
315
371
|
}
|
|
316
372
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Internal recursive helper for creating deep immutable copies with structural sharing.
|
|
375
|
+
* Only clones nodes along the path where changes occur.
|
|
376
|
+
*/
|
|
377
|
+
export declare function setDeepValue(obj: unknown, keys: string[], index: number, value: unknown): unknown;
|
|
378
|
+
|
|
379
|
+
/** Helper to convert numeric string to number for array indexing. */
|
|
380
|
+
export declare type StringKeyToNumber<S extends string> = S extends `${infer N extends number}` ? N : S;
|
|
322
381
|
|
|
323
382
|
export declare interface Subscriber {
|
|
324
383
|
execute(): void;
|