-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): nest array remove initial-value logic in destory #4052
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那么问题来了,是否应该在组件销毁的时候重置 schema 上所声明的 initialValue呢? 在我的部分使用场景中,其实有跟 #4024 楼主类似的疑惑, 我使用 form 上的 initialValues 是期望 reset 的时候能重置回去整个表单的数据; 如果 schema 上配置的 default 即 initialValue 对表单的 initialValues 产生了影响,还是是非常费解的。 所以我给出一下总结和建议
- 使用原始方案,对form.initialValues 进行更新
2.按照我的方案,如果有删除,那么对有 schema 上进行 initalValue(default)标注的 path 所对应的 form.initialValues 中的字段进行删除 - 添加一个类似 IFormMergeStrategy 的属性来让用户决定如何判断
- 重新添加一个 freeze 初始值,这将是一个不会变的 form 初始值,以方便用户在重置的时候直接 reset 到这个最初的,不会被改变的初始值
@@ -514,6 +514,7 @@ test('array field remove memo leak', async () => { | |||
expect(initialValuesChange).toBeCalledTimes(0) | |||
}) | |||
|
|||
// add sandbox https://codesandbox.io/p/devbox/lingering-violet-jwr565 | |||
test('nest array remove', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
场景一:嵌套数组删除逻辑测试代码, 其中深层的数组的 initialValue 属性会改变 form.initialValues 值,针对这个测试, 我补充了一个 sandbox
expect( | ||
form.initialValues.metrics?.[1]?.content?.[0]?.attr | ||
).not.toBeUndefined() | ||
}) | ||
|
||
|
||
test('nest array remove for #4024', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
情况二:针对 #4024 中反馈的问题, 我补充了一个测试用例
if (forceClear) { | ||
form.deleteValuesIn(path) | ||
} | ||
// 在 schema 上有定义 initialValue (JSX prop name: default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前方案: 根据 schema 上的initialValues,在销毁时对 form.initialValues 进行现场恢复
@@ -588,11 +589,84 @@ test('nest array remove', async () => { | |||
expect(form.fields['metrics.0.content.0.attr']).not.toBeUndefined() | |||
await metrics.remove(1) | |||
expect(form.fields['metrics.0.content.0.attr']).not.toBeUndefined() | |||
// TODO!! 测试不通过 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是按照我当前的修复方案,form.initialValues 会被重置, 所以这个测试语句不通过
|
rebase 玩坏了, 这里重开 #4053 |
Before submitting a pull request, please make sure the following is done...
master
orformily_next
.npm test
).npm run lint
) - we've done our best to make sure these rules match our internal linting guidelines.Please do not delete the above content
try fix #4024
What have you changed?