yuustate 3.11.0 → 3.11.1
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/esm/react.mjs +12 -1
- package/package.json +1 -1
- package/react.js +12 -1
package/esm/react.mjs
CHANGED
|
@@ -3,7 +3,15 @@ import { isClient, initStore, getHash, noop } from 'yuustate/vanilla';
|
|
|
3
3
|
|
|
4
4
|
const useIsomorphicLayoutEffect = isClient ? useLayoutEffect : useEffect;
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const DATE_METHOD_REGEX = /^(?:to|get)[A-Z]/;
|
|
7
|
+
const getValueByPath = (obj, path) => {
|
|
8
|
+
return path.reduce((acc, key) => {
|
|
9
|
+
if (acc instanceof Date && DATE_METHOD_REGEX.test(key)) {
|
|
10
|
+
return acc[key]();
|
|
11
|
+
}
|
|
12
|
+
return acc == null ? void 0 : acc[key];
|
|
13
|
+
}, obj);
|
|
14
|
+
};
|
|
7
15
|
const isPrefixPath = (candidatePrefix, targetPath) => {
|
|
8
16
|
if (candidatePrefix.length >= targetPath.length) return false;
|
|
9
17
|
for (let i = 0; i < candidatePrefix.length; i++) {
|
|
@@ -39,6 +47,9 @@ const useStoreStateProxy = (storeState) => {
|
|
|
39
47
|
const newPath = [...path, key];
|
|
40
48
|
track(newPath);
|
|
41
49
|
const value = obj[key];
|
|
50
|
+
if (target instanceof Date && typeof value === "function" && DATE_METHOD_REGEX.test(key)) {
|
|
51
|
+
return value.bind(target);
|
|
52
|
+
}
|
|
42
53
|
return createDeepProxy(value, newPath);
|
|
43
54
|
}
|
|
44
55
|
});
|
package/package.json
CHANGED
package/react.js
CHANGED
|
@@ -5,7 +5,15 @@ var vanilla = require('yuustate/vanilla');
|
|
|
5
5
|
|
|
6
6
|
const useIsomorphicLayoutEffect = vanilla.isClient ? react.useLayoutEffect : react.useEffect;
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const DATE_METHOD_REGEX = /^(?:to|get)[A-Z]/;
|
|
9
|
+
const getValueByPath = (obj, path) => {
|
|
10
|
+
return path.reduce((acc, key) => {
|
|
11
|
+
if (acc instanceof Date && DATE_METHOD_REGEX.test(key)) {
|
|
12
|
+
return acc[key]();
|
|
13
|
+
}
|
|
14
|
+
return acc == null ? void 0 : acc[key];
|
|
15
|
+
}, obj);
|
|
16
|
+
};
|
|
9
17
|
const isPrefixPath = (candidatePrefix, targetPath) => {
|
|
10
18
|
if (candidatePrefix.length >= targetPath.length) return false;
|
|
11
19
|
for (let i = 0; i < candidatePrefix.length; i++) {
|
|
@@ -41,6 +49,9 @@ const useStoreStateProxy = (storeState) => {
|
|
|
41
49
|
const newPath = [...path, key];
|
|
42
50
|
track(newPath);
|
|
43
51
|
const value = obj[key];
|
|
52
|
+
if (target instanceof Date && typeof value === "function" && DATE_METHOD_REGEX.test(key)) {
|
|
53
|
+
return value.bind(target);
|
|
54
|
+
}
|
|
44
55
|
return createDeepProxy(value, newPath);
|
|
45
56
|
}
|
|
46
57
|
});
|