atomaric 0.0.34 → 0.0.35
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/package.json +3 -3
- package/types/{model.d.ts → index.d.ts} +15 -4
- package/types/paths.ts +12 -12
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atomaric",
|
|
3
3
|
"description": "Manage your project state",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.35",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./build/atomaric.umd.cjs",
|
|
7
7
|
"module": "./build/atomaric.js",
|
|
8
|
-
"types": "./types/
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./types/
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
12
|
"require": "./build/atomaric.umd.cjs",
|
|
13
13
|
"import": "./build/atomaric.js"
|
|
14
14
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
|
-
import { Path,
|
|
2
|
+
import { Path, TPathValue } from './paths';
|
|
3
|
+
|
|
4
|
+
export interface Register {}
|
|
3
5
|
|
|
4
6
|
type Sunscriber<Value> = (value: Value) => void;
|
|
5
7
|
|
|
@@ -66,8 +68,8 @@ export type ObjectActions<Value> = UpdateAction<Value> & {
|
|
|
66
68
|
/** pass partial value to update some deep values by flat path */
|
|
67
69
|
setDeepPartial: <
|
|
68
70
|
ValuePath extends Path<Value, Sep>,
|
|
69
|
-
Val extends
|
|
70
|
-
Sep extends string =
|
|
71
|
+
Val extends TPathValue<Value, Sep, ValuePath>,
|
|
72
|
+
Sep extends string = ObjectActionsSetDeepPartial,
|
|
71
73
|
>(
|
|
72
74
|
path: ValuePath,
|
|
73
75
|
value: Partial<Val> | ((value: Val) => Partial<Val>),
|
|
@@ -75,6 +77,12 @@ export type ObjectActions<Value> = UpdateAction<Value> & {
|
|
|
75
77
|
) => void;
|
|
76
78
|
};
|
|
77
79
|
|
|
80
|
+
export type ObjectActionsSetDeepPartial = Register extends {
|
|
81
|
+
keyPathSeparator: infer Separator extends string;
|
|
82
|
+
}
|
|
83
|
+
? Separator
|
|
84
|
+
: '.';
|
|
85
|
+
|
|
78
86
|
export type BooleanActions = {
|
|
79
87
|
/** toggle current value between true/false */
|
|
80
88
|
toggle: () => void;
|
|
@@ -159,4 +167,7 @@ export function atom<Value, Actions extends Record<string, Function> = {}>(
|
|
|
159
167
|
): Atom<Value, Actions>;
|
|
160
168
|
|
|
161
169
|
/** invoke this function before all atom usages */
|
|
162
|
-
export function configureAtomaric(options: {
|
|
170
|
+
export function configureAtomaric(options: {
|
|
171
|
+
useSyncExternalStore: typeof useSyncExternalStore;
|
|
172
|
+
keyPathSeparator: ObjectActionsSetDeepPartial;
|
|
173
|
+
}): void;
|
package/types/paths.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Path<T, Sep extends string> = T extends any ? PathInternal<T, Sep> : never;
|
|
2
|
-
|
|
2
|
+
export type PathValue<T, Sep extends string, ValuePath extends Path<T, Sep>> = TPathValue<T, Sep, ValuePath>;
|
|
3
3
|
|
|
4
4
|
/////////////////////////////////////////////////////////////////////////
|
|
5
5
|
/////////////////////////////////////////////////////////////////////////
|
|
@@ -20,7 +20,7 @@ type PathInternal<T, Sep extends string, TraversedTypes = T> = T extends Readonl
|
|
|
20
20
|
[K in keyof T]-?: PathImpl<K & string, Sep, T[K], TraversedTypes>;
|
|
21
21
|
}[keyof T];
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
|
24
24
|
|
|
25
25
|
type PathImpl<K extends string | number, Sep extends string, V, TraversedTypes> = V extends
|
|
26
26
|
| Primitive
|
|
@@ -30,13 +30,13 @@ type PathImpl<K extends string | number, Sep extends string, V, TraversedTypes>
|
|
|
30
30
|
? `${K}`
|
|
31
31
|
: `${K}` | `${K}${Sep}${PathInternal<V, Sep, TraversedTypes | V>}`;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
type ArrayKey = number;
|
|
34
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
35
|
+
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
36
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
37
37
|
|
|
38
38
|
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
39
|
-
|
|
39
|
+
type IsEqual<T1, T2> = T1 extends T2
|
|
40
40
|
? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
41
41
|
? true
|
|
42
42
|
: false
|
|
@@ -56,15 +56,15 @@ export type IsEqual<T1, T2> = T1 extends T2
|
|
|
56
56
|
////////////////////////////////////////////////////////////////////////////
|
|
57
57
|
////////////////////////////////////////////////////////////////////////////
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
type TPathValue<T, Sep extends string, P extends Path<T, Sep> | ArrayPath<T, Sep>> = T extends any
|
|
60
60
|
? P extends `${infer K}${Sep}${infer R}`
|
|
61
61
|
? K extends keyof T
|
|
62
62
|
? R extends Path<T[K], Sep>
|
|
63
|
-
?
|
|
63
|
+
? TPathValue<T[K], Sep, R>
|
|
64
64
|
: never
|
|
65
65
|
: K extends `${ArrayKey}`
|
|
66
66
|
? T extends ReadonlyArray<infer V>
|
|
67
|
-
?
|
|
67
|
+
? TPathValue<V, Sep, R & Path<V, Sep>>
|
|
68
68
|
: never
|
|
69
69
|
: never
|
|
70
70
|
: P extends keyof T
|
|
@@ -76,7 +76,7 @@ export type PathValue<T, Sep extends string, P extends Path<T, Sep> | ArrayPath<
|
|
|
76
76
|
: never
|
|
77
77
|
: never;
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
type ArrayPath<T, Sep extends string> = T extends any ? ArrayPathInternal<T, Sep> : never;
|
|
80
80
|
|
|
81
81
|
type ArrayPathInternal<T, Sep extends string, TraversedTypes = T> = T extends ReadonlyArray<infer V>
|
|
82
82
|
? IsTuple<T> extends true
|
|
@@ -106,4 +106,4 @@ type ArrayPathImpl<K extends string | number, Sep extends string, V, TraversedTy
|
|
|
106
106
|
? never
|
|
107
107
|
: `${K}${Sep}${ArrayPathInternal<V, Sep, TraversedTypes | V>}`;
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|