yuustate 3.11.1 → 3.11.3
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 +5 -5
- package/package.json +1 -1
- package/react.js +4 -4
package/esm/react.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useLayoutEffect, useEffect, useRef, useSyncExternalStore, useCallback, useMemo, useState } from 'react';
|
|
1
|
+
import { useLayoutEffect, useEffect, useRef, useSyncExternalStore, useCallback, useMemo, isValidElement, useState } from 'react';
|
|
2
2
|
import { isClient, initStore, getHash, noop } from 'yuustate/vanilla';
|
|
3
3
|
|
|
4
4
|
const useIsomorphicLayoutEffect = isClient ? useLayoutEffect : useEffect;
|
|
5
5
|
|
|
6
|
-
const DATE_METHOD_REGEX = /^(
|
|
6
|
+
const DATE_METHOD_REGEX = /^((to|get)[A-Z]|valueOf)/;
|
|
7
7
|
const getValueByPath = (obj, path) => {
|
|
8
8
|
return path.reduce((acc, key) => {
|
|
9
|
-
if (acc instanceof Date && DATE_METHOD_REGEX.test(key)) {
|
|
9
|
+
if (acc instanceof Date && typeof key === "string" && DATE_METHOD_REGEX.test(key)) {
|
|
10
10
|
return acc[key]();
|
|
11
11
|
}
|
|
12
12
|
return acc == null ? void 0 : acc[key];
|
|
@@ -36,7 +36,7 @@ const useStoreStateProxy = (storeState) => {
|
|
|
36
36
|
const track = (path) => usedPathsRef.current.push(path);
|
|
37
37
|
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
38
38
|
const createDeepProxy = (target, path = []) => {
|
|
39
|
-
if (typeof target !== "object" || target === null) {
|
|
39
|
+
if (typeof target !== "object" || target === null || isValidElement(target)) {
|
|
40
40
|
return target;
|
|
41
41
|
}
|
|
42
42
|
if (proxyCache.has(target)) {
|
|
@@ -47,7 +47,7 @@ const useStoreStateProxy = (storeState) => {
|
|
|
47
47
|
const newPath = [...path, key];
|
|
48
48
|
track(newPath);
|
|
49
49
|
const value = obj[key];
|
|
50
|
-
if (target instanceof Date && typeof value === "function" && DATE_METHOD_REGEX.test(key)) {
|
|
50
|
+
if (target instanceof Date && typeof value === "function" && typeof key === "string" && DATE_METHOD_REGEX.test(key)) {
|
|
51
51
|
return value.bind(target);
|
|
52
52
|
}
|
|
53
53
|
return createDeepProxy(value, newPath);
|
package/package.json
CHANGED
package/react.js
CHANGED
|
@@ -5,10 +5,10 @@ var vanilla = require('yuustate/vanilla');
|
|
|
5
5
|
|
|
6
6
|
const useIsomorphicLayoutEffect = vanilla.isClient ? react.useLayoutEffect : react.useEffect;
|
|
7
7
|
|
|
8
|
-
const DATE_METHOD_REGEX = /^(
|
|
8
|
+
const DATE_METHOD_REGEX = /^((to|get)[A-Z]|valueOf)/;
|
|
9
9
|
const getValueByPath = (obj, path) => {
|
|
10
10
|
return path.reduce((acc, key) => {
|
|
11
|
-
if (acc instanceof Date && DATE_METHOD_REGEX.test(key)) {
|
|
11
|
+
if (acc instanceof Date && typeof key === "string" && DATE_METHOD_REGEX.test(key)) {
|
|
12
12
|
return acc[key]();
|
|
13
13
|
}
|
|
14
14
|
return acc == null ? void 0 : acc[key];
|
|
@@ -38,7 +38,7 @@ const useStoreStateProxy = (storeState) => {
|
|
|
38
38
|
const track = (path) => usedPathsRef.current.push(path);
|
|
39
39
|
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
40
40
|
const createDeepProxy = (target, path = []) => {
|
|
41
|
-
if (typeof target !== "object" || target === null) {
|
|
41
|
+
if (typeof target !== "object" || target === null || react.isValidElement(target)) {
|
|
42
42
|
return target;
|
|
43
43
|
}
|
|
44
44
|
if (proxyCache.has(target)) {
|
|
@@ -49,7 +49,7 @@ const useStoreStateProxy = (storeState) => {
|
|
|
49
49
|
const newPath = [...path, key];
|
|
50
50
|
track(newPath);
|
|
51
51
|
const value = obj[key];
|
|
52
|
-
if (target instanceof Date && typeof value === "function" && DATE_METHOD_REGEX.test(key)) {
|
|
52
|
+
if (target instanceof Date && typeof value === "function" && typeof key === "string" && DATE_METHOD_REGEX.test(key)) {
|
|
53
53
|
return value.bind(target);
|
|
54
54
|
}
|
|
55
55
|
return createDeepProxy(value, newPath);
|