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

perform switch and case logic #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daxuewen
Copy link
Contributor

@daxuewen daxuewen commented Oct 14, 2018

perform switch and case logic

@coveralls
Copy link

coveralls commented Oct 14, 2018

Pull Request Test Coverage Report for Build 8

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 3: 0.0%
Covered Lines: 35
Relevant Lines: 35

💛 - Coveralls

README.md Outdated
let testValue = 4;

<Switch value={testValue}>
<Case value={[1, 2]}>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果testValue本身就是数组怎么办?

Copy link
Contributor Author

@daxuewen daxuewen Oct 23, 2018

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>

目前业务里遇到的场景数组和对象并不常见。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然这个是开放给社区的库了,我觉得最好考虑到不同的场景来搞

Copy link
Contributor Author

@daxuewen daxuewen Oct 25, 2018

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>

Copy link
Owner

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很有可能会影响优化

Copy link
Contributor Author

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是很建议提供这个属性,对于复杂的场景已经有Match可以做了,Switch应该是一个保持高度简洁的东西

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我也考虑过,这个和上面的testValue有些联系,如果testValue是数组和对象, 可能需要自定义的equal

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是数组和对象,也要求===会如何,我们强行和JS本身的switch一致的话……

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.

4 participants