Skip to content
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): initial value should clear in destroy #4053

Open
wants to merge 1 commit into
base: formily_next
Choose a base branch
from

Conversation

charlzyx
Copy link
Contributor

Before submitting a pull request, please make sure the following is done...

  • Ensure the pull request title and commit message follow the Commit Specific in English.
  • Fork the repo and create your branch from master or formily_next.
  • If you've added code that should be tested, add tests!
  • If you've changed APIs, update the documentation.
  • Ensure the test suite passes (npm test).
  • Make sure your code lints (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


What have you changed?

变更 destory 中 initialValues 处理逻辑

before: 子组件销毁调用的 patchFieldStates() 处理中, destory 默认不清理 form.initialValues, 在嵌套数组的情况下, 会出现一下问题 #4024
after: 在 destory 中判断, 如果 field 的 schema 存在不为 undefined 的 initialValue 属性(即 default), 在销毁的时候进行删除, 以还原 form.initialValues

讨论:

那么问题来了,是否应该在组件销毁的时候重置 schema 上所声明的 initialValue呢? 在我的部分使用场景中,其实有跟 #4024 楼主类似的疑惑, 我使用 form 上的 initialValues 是期望 reset 的时候能重置回去整个表单的数据; 如果 schema 上配置的 default 即 initialValue 对表单的 initialValues 产生了影响,还是是非常费解的。 所以我给出一下总结和建议

  1. 使用原始方案,对form.initialValues 进行更新
  2. 按照我的方案,如果有删除,那么对有 schema 上进行 initalValue(default)标注的 path 所对应的 form.initialValues 中的字段进行删除
  3. 添加一个类似 IFormMergeStrategy 的属性来让用户决定如何判断
  4. 新增一个 freezeInitialValue 初始值,这将是一个不会变的 form 初始值,以方便用户在重置的时候直接 reset 到这个最初的,不会被改变的初始值

@charlzyx charlzyx changed the title fix: 🐛 initial value should clear in destroy fix(core): initial value should clear in destroy Dec 29, 2023
@charlzyx charlzyx marked this pull request as ready for review December 29, 2023 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant