react-state-monad 1.0.21 → 1.0.23
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/index.cjs +6 -7
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +6 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -43,18 +43,17 @@ function useFieldState(state, field) {
|
|
43
43
|
}
|
44
44
|
function useRemapKeysState(state) {
|
45
45
|
if (!state.hasValue) {
|
46
|
-
return
|
46
|
+
return {};
|
47
47
|
}
|
48
48
|
if (Array.isArray(state.value)) {
|
49
49
|
console.warn("useRemapKeysState should be used with objects, use useRemapArray for arrays");
|
50
|
-
return
|
50
|
+
return {};
|
51
51
|
}
|
52
52
|
const keys = Object.keys(state.value);
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
});
|
57
|
-
return map;
|
53
|
+
return keys.reduce((acc, key) => {
|
54
|
+
acc[key] = useFieldState(state, key);
|
55
|
+
return acc;
|
56
|
+
}, {});
|
58
57
|
}
|
59
58
|
|
60
59
|
// src/implementations/emptyState.ts
|
package/dist/index.d.cts
CHANGED
@@ -79,15 +79,14 @@ type ValidFieldFrom<TObject, TField> = {
|
|
79
79
|
*/
|
80
80
|
declare function useFieldState<TOriginal, TField>(state: StateObject<TOriginal>, field: ValidFieldFrom<TOriginal, TField>): StateObject<TField>;
|
81
81
|
/**
|
82
|
-
* Hook that remaps the keys of
|
83
|
-
* allowing for independent updates of each key while keeping the overall object state synchronized.
|
82
|
+
* Hook that remaps the keys of a state object to a record of StateObjects.
|
84
83
|
*
|
85
84
|
* @template TOriginal - The type of the original state object.
|
86
|
-
* @
|
87
|
-
* @
|
88
|
-
*
|
85
|
+
* @template TField - The type of the field value to be derived.
|
86
|
+
* @param state - The StateObject containing the original state.
|
87
|
+
* @returns A record where each key is mapped to a new StateObject for the corresponding field.
|
89
88
|
*/
|
90
|
-
declare function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>):
|
89
|
+
declare function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<string, StateObject<TField>>;
|
91
90
|
|
92
91
|
/**
|
93
92
|
* Hook that allows you to derive and update a specific element in an array within a StateObject.
|
package/dist/index.d.ts
CHANGED
@@ -79,15 +79,14 @@ type ValidFieldFrom<TObject, TField> = {
|
|
79
79
|
*/
|
80
80
|
declare function useFieldState<TOriginal, TField>(state: StateObject<TOriginal>, field: ValidFieldFrom<TOriginal, TField>): StateObject<TField>;
|
81
81
|
/**
|
82
|
-
* Hook that remaps the keys of
|
83
|
-
* allowing for independent updates of each key while keeping the overall object state synchronized.
|
82
|
+
* Hook that remaps the keys of a state object to a record of StateObjects.
|
84
83
|
*
|
85
84
|
* @template TOriginal - The type of the original state object.
|
86
|
-
* @
|
87
|
-
* @
|
88
|
-
*
|
85
|
+
* @template TField - The type of the field value to be derived.
|
86
|
+
* @param state - The StateObject containing the original state.
|
87
|
+
* @returns A record where each key is mapped to a new StateObject for the corresponding field.
|
89
88
|
*/
|
90
|
-
declare function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>):
|
89
|
+
declare function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<string, StateObject<TField>>;
|
91
90
|
|
92
91
|
/**
|
93
92
|
* Hook that allows you to derive and update a specific element in an array within a StateObject.
|
package/dist/index.js
CHANGED
@@ -9,18 +9,17 @@ function useFieldState(state, field) {
|
|
9
9
|
}
|
10
10
|
function useRemapKeysState(state) {
|
11
11
|
if (!state.hasValue) {
|
12
|
-
return
|
12
|
+
return {};
|
13
13
|
}
|
14
14
|
if (Array.isArray(state.value)) {
|
15
15
|
console.warn("useRemapKeysState should be used with objects, use useRemapArray for arrays");
|
16
|
-
return
|
16
|
+
return {};
|
17
17
|
}
|
18
18
|
const keys = Object.keys(state.value);
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
});
|
23
|
-
return map;
|
19
|
+
return keys.reduce((acc, key) => {
|
20
|
+
acc[key] = useFieldState(state, key);
|
21
|
+
return acc;
|
22
|
+
}, {});
|
24
23
|
}
|
25
24
|
|
26
25
|
// src/implementations/emptyState.ts
|