-
Notifications
You must be signed in to change notification settings - Fork 10
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
Optimize validate()
behavior when validation disabled
#75
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NIP: 我突然觉得 disabled 的定位应该重新明确一下…
除了看不见之外,还意味着什么?
比如“残留”着上次的状态以待后续潜在的重新 enabled 后接着用?
比如 disabled 的时候 set reset (以及后面的 touched)这些接口该如何理解?
比如一个 disabled 的 state 作为子 state 存在的时候,父 state 的 value 应该能拿到它的值吗?
诸如此类,等等
比如我就会想:
disabled 的时候要不要不清 error?
如果不清,那么转为 enabled 的那一刻,应该清了重新等 validate 或干脆不 active 吗?
如果都不清,那么 disable when 变更的心智模型就跟 validators 变更有区别了,这确实无所谓吗?
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.
我们的表单状态模型是一棵 state 树,每个节点都是一个 state
在我自己的理解里,关于 disabled 的最直接的诉求是这样的:被 disabled 的 state,就像从当前 state 树上被摘掉了一样;原因很简单,因为这个 feature 对标的就是表单中的条件输入(conditional input)的场景,而这个场景对应的 input,就像是从当前 UI 树上被摘掉了一样
因此在理想的情况下
validate()
),它并不会随之去执行自己的校验value
不体现到最终 state 树的value
里其中,1 已经做到了,2 对应对应晨哥这个 PR 里的改动;至于 3,考虑到我们希望提供类型安全的
value
,可预见的会比较麻烦,而且对表单页面的开发者意义不大,因为多给一个值几乎总是不会有问题的,他不去消费就好了,所以我理解 3 可以不去管这样的话
就不是特别严谨,严谨一点说是:被 disabled 的 state,就像从被当前 state 树上藏起来了一样;这个也很好理解,就像我们希望不展示一块界面的时候,也可能不是真的把它从 UI 树上摘掉,而是把它通过 css 藏起来
基于以上的前提,你上边提到的问题几乎都能得到一个自然的答案:
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.
这你是从哪里引用到的…
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.
自己说的,自己引用..