-
Notifications
You must be signed in to change notification settings - Fork 4
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
perform switch and case logic #4
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
let testValue = 4; | ||
|
||
<Switch value={testValue}> | ||
<Case value={[1, 2]}> |
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.
如果testValue
本身就是数组怎么办?
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.
如果testValue
本身就是数组或者对象,匹配的需要写成下面这样。
<Case value={[testValue]}>...</Case>
目前业务里遇到的场景数组和对象并不常见。
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.
准备改成:支持value和values两种,想匹配多个使用values
<Case value={testValue}>...</Case>
<Case values={[testValue]}>...</Case>
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.
先只保留value
,不允许数组吧,我最近在思考把<Whether>
和<Switch>
在babel插件层面做优化的可能性,这个values
很有可能会影响优化
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.
只保留value
的话有些场景覆盖不到,babel优化的时候,values
应该可以先转成多个value
来解决吧
src/Switch.js
Outdated
Switch.propTypes = { | ||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]).isRequired, | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired, | ||
equal: PropTypes.func |
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.
不是很建议提供这个属性,对于复杂的场景已经有Match
可以做了,Switch
应该是一个保持高度简洁的东西
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.
这个我也考虑过,这个和上面的testValue
有些联系,如果testValue
是数组和对象, 可能需要自定义的equal
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.
如果是数组和对象,也要求===
会如何,我们强行和JS本身的switch
一致的话……
perform switch and case logic