@rainbow-oh/yee-c 0.14.4 → 0.14.5
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/cjs/Form/form-store.js +3 -3
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Form/form-store.js +7 -3
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Form/form-store.test.ts +19 -0
- package/src/Form/form-store.ts +7 -3
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -144,6 +144,25 @@ describe('FormStore.initialize initialValues', () => {
|
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
describe('FormStore.initialize re-binds callbacks', () => {
|
|
148
|
+
it('re-registers callbacks on remount but applies initialValues once only', () => {
|
|
149
|
+
const store = new FormStore();
|
|
150
|
+
const first = vi.fn();
|
|
151
|
+
const second = vi.fn();
|
|
152
|
+
|
|
153
|
+
store.initialize({ initialValues: { a: 1 }, callbacks: { onValuesChange: first } });
|
|
154
|
+
// 模拟 <Form> 卸载后重挂载(form 实例由外层 useForm 持有而存活):
|
|
155
|
+
// 新一次挂载传入新的 useEvent 闭包,store 必须改绑到它
|
|
156
|
+
store.initialize({ initialValues: { a: 999 }, callbacks: { onValuesChange: second } });
|
|
157
|
+
|
|
158
|
+
store.setFieldsValue({ a: 2 });
|
|
159
|
+
expect(first).not.toHaveBeenCalled();
|
|
160
|
+
expect(second).toHaveBeenCalledTimes(1);
|
|
161
|
+
// initialValues 仍只在首次初始化生效
|
|
162
|
+
expect(store.getFieldValue('a')).toBe(2);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
147
166
|
describe('FormStore.setFieldsValue with clear trigger', () => {
|
|
148
167
|
it('merges over the store instead of replacing it', () => {
|
|
149
168
|
const store = new FormStore();
|
package/src/Form/form-store.ts
CHANGED
|
@@ -70,6 +70,13 @@ export class FormStore {
|
|
|
70
70
|
initialValues?: Store;
|
|
71
71
|
callbacks?: Callbacks;
|
|
72
72
|
}) => {
|
|
73
|
+
// callbacks 每次挂载重绑:form 实例可由外层 useForm 持有、跨越 <Form> 卸载/重挂载存活,
|
|
74
|
+
// 若只在此处注册一次,重挂载后 store 仍持旧挂载的 useEvent 闭包,其 ref 已随旧实例
|
|
75
|
+
// 死亡(不再更新),onValuesChange 等会以过期闭包执行。
|
|
76
|
+
if (callbacks) {
|
|
77
|
+
this.setCallbacks(callbacks);
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
if (!this.initialized) {
|
|
74
81
|
this.initialized = true;
|
|
75
82
|
|
|
@@ -78,9 +85,6 @@ export class FormStore {
|
|
|
78
85
|
this.initialValues = JSON.parse(JSON.stringify(initialValues));
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
if (callbacks) {
|
|
82
|
-
this.setCallbacks(callbacks);
|
|
83
|
-
}
|
|
84
88
|
// Only refresh field entities, do not notify watchers (no value changes to watch during initialization)
|
|
85
89
|
this.fieldEntities.forEach((entity) => {
|
|
86
90
|
entity?.onStoreChange();
|