@zat-design/sisyphus-react 3.13.2-beta.3 → 3.13.2-beta.4
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.
@@ -51,23 +51,39 @@ function useWatch(dependencies, form, wait) {
|
|
51
51
|
getInternalHooks = formInstance.getInternalHooks;
|
52
52
|
var _getInternalHooks = getInternalHooks(HOOK_MARK),
|
53
53
|
registerWatch = _getInternalHooks.registerWatch;
|
54
|
+
// 创建回调函数
|
54
55
|
var callback = function callback() {
|
56
|
+
// 只获取一次新值
|
55
57
|
var newValue = getFieldsValue(_dependencies);
|
56
58
|
var nextValueStr = stringify(newValue);
|
57
59
|
// Compare stringify in case it's nest object
|
58
60
|
if (valueStrRef.current !== nextValueStr) {
|
59
61
|
valueStrRef.current = nextValueStr;
|
60
|
-
|
62
|
+
// 关键修改:使用已获取的newValue,避免重复调用getFieldsValue
|
63
|
+
setValue(newValue);
|
61
64
|
}
|
62
65
|
};
|
63
66
|
// 增加防抖
|
67
|
+
var cancelDebounce = null;
|
64
68
|
if (wait) {
|
65
|
-
|
69
|
+
var debouncedCallback = debounce(callback, wait);
|
70
|
+
callback = debouncedCallback;
|
71
|
+
cancelDebounce = function cancelDebounce() {
|
72
|
+
return debouncedCallback.cancel();
|
73
|
+
};
|
66
74
|
}
|
75
|
+
// 注册监听
|
67
76
|
var cancelRegister = registerWatch(callback);
|
77
|
+
// 设置初始值
|
68
78
|
var initialValue = getFieldsValue(_dependencies);
|
69
79
|
setValue(initialValue);
|
70
|
-
|
80
|
+
// 清理函数
|
81
|
+
return function () {
|
82
|
+
cancelRegister();
|
83
|
+
if (cancelDebounce) {
|
84
|
+
cancelDebounce();
|
85
|
+
}
|
86
|
+
};
|
71
87
|
},
|
72
88
|
// We do not need re-register since namePath content is the same
|
73
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -61,23 +61,39 @@ function useWatch(dependencies, form, wait) {
|
|
61
61
|
getInternalHooks = formInstance.getInternalHooks;
|
62
62
|
var _getInternalHooks = getInternalHooks(_FieldContext.HOOK_MARK),
|
63
63
|
registerWatch = _getInternalHooks.registerWatch;
|
64
|
+
// 创建回调函数
|
64
65
|
var callback = function callback() {
|
66
|
+
// 只获取一次新值
|
65
67
|
var newValue = getFieldsValue(_dependencies);
|
66
68
|
var nextValueStr = stringify(newValue);
|
67
69
|
// Compare stringify in case it's nest object
|
68
70
|
if (valueStrRef.current !== nextValueStr) {
|
69
71
|
valueStrRef.current = nextValueStr;
|
70
|
-
|
72
|
+
// 关键修改:使用已获取的newValue,避免重复调用getFieldsValue
|
73
|
+
setValue(newValue);
|
71
74
|
}
|
72
75
|
};
|
73
76
|
// 增加防抖
|
77
|
+
var cancelDebounce = null;
|
74
78
|
if (wait) {
|
75
|
-
|
79
|
+
var debouncedCallback = (0, _lodash.debounce)(callback, wait);
|
80
|
+
callback = debouncedCallback;
|
81
|
+
cancelDebounce = function cancelDebounce() {
|
82
|
+
return debouncedCallback.cancel();
|
83
|
+
};
|
76
84
|
}
|
85
|
+
// 注册监听
|
77
86
|
var cancelRegister = registerWatch(callback);
|
87
|
+
// 设置初始值
|
78
88
|
var initialValue = getFieldsValue(_dependencies);
|
79
89
|
setValue(initialValue);
|
80
|
-
|
90
|
+
// 清理函数
|
91
|
+
return function () {
|
92
|
+
cancelRegister();
|
93
|
+
if (cancelDebounce) {
|
94
|
+
cancelDebounce();
|
95
|
+
}
|
96
|
+
};
|
81
97
|
},
|
82
98
|
// We do not need re-register since namePath content is the same
|
83
99
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|