@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-oh/yee-c",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "description": "yee basic components",
5
5
  "keywords": [
6
6
  "react",
@@ -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();
@@ -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();
package/src/version.ts CHANGED
@@ -4,7 +4,7 @@ declare global {
4
4
  }
5
5
  }
6
6
 
7
- export const version = "0.14.4";
7
+ export const version = "0.14.5";
8
8
 
9
9
  if (typeof window !== 'undefined') {
10
10
  window.__yee_c_version__ = version;