@but212/atom-effect 0.27.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 +60 -0
- package/dist/index.mjs +239 -180
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,17 @@ export declare class AtomError extends Error {
|
|
|
31
31
|
constructor(message: string, cause?: Error | null, recoverable?: boolean);
|
|
32
32
|
}
|
|
33
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
|
+
|
|
34
45
|
/**
|
|
35
46
|
* Atom options.
|
|
36
47
|
*/
|
|
@@ -47,6 +58,11 @@ export declare interface AtomOptions {
|
|
|
47
58
|
*/
|
|
48
59
|
export declare function batch<T>(fn: () => T): T;
|
|
49
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
|
+
|
|
50
66
|
/**
|
|
51
67
|
* Creates a computed value.
|
|
52
68
|
* @param fn - Computation function
|
|
@@ -186,6 +202,11 @@ export declare interface EffectOptions {
|
|
|
186
202
|
onError?: (error: unknown) => void;
|
|
187
203
|
}
|
|
188
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
|
+
|
|
189
210
|
/**
|
|
190
211
|
* Readonly atom check.
|
|
191
212
|
*
|
|
@@ -203,6 +224,36 @@ export declare function isComputed(obj: unknown): obj is ComputedAtom;
|
|
|
203
224
|
*/
|
|
204
225
|
export declare function isEffect(obj: unknown): obj is EffectObject;
|
|
205
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
|
+
|
|
206
257
|
export declare interface PoolStats {
|
|
207
258
|
acquired: number;
|
|
208
259
|
released: number;
|
|
@@ -319,6 +370,15 @@ declare interface SchedulerJobObject {
|
|
|
319
370
|
_nextEpoch?: number;
|
|
320
371
|
}
|
|
321
372
|
|
|
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;
|
|
381
|
+
|
|
322
382
|
export declare interface Subscriber {
|
|
323
383
|
execute(): void;
|
|
324
384
|
}
|