-
Notifications
You must be signed in to change notification settings - Fork 238
Conversation
@@ -143,7 +143,7 @@ function useCollapsed( | |||
onCollapse: BasicLayoutProps['onCollapse'], | |||
): [boolean | undefined, BasicLayoutProps['onCollapse']] { | |||
warning( | |||
collapsed === undefined || onCollapse === undefined, | |||
(collapsed === undefined) === (onCollapse === undefined), |
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.
不能用&&,最终目的是断言这两个属性需要同时设置,或者同时不设置。异或取反!
@@ -143,7 +143,7 @@ function useCollapsed( | |||
onCollapse: BasicLayoutProps['onCollapse'], | |||
): [boolean | undefined, BasicLayoutProps['onCollapse']] { | |||
warning( | |||
collapsed === undefined || onCollapse === undefined, | |||
(collapsed === undefined) === (onCollapse === undefined), |
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.
(collapsed === undefined) === (onCollapse === undefined), | |
(collapsed !== undefined && onCollapse !== undefined) || (collapsed === undefined && onCollapse === undefined) |
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.
不一致,两个都不为 undefined 时也不应该 warning。
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.
两个都不为undefined的时候,两边都是false,false===false,结果是true,所以不会warning。
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.
用位运算表示 这是一个 <同或> 的问题
a | b | a⊙b |
---|---|---|
0 | 0 | 1 |
1 | 1 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
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.
(collapsed !== undefined && onCollapse !== undefined) || (collapsed === undefined && onCollapse === undefined)
这种写法更易读
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.
可读性其实更重要一点。
Fix set onCollapse and collapsed warning
before
after