Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

fix collapsed warning #81

Merged
merged 1 commit into from
Aug 12, 2019
Merged

Conversation

blackraindrop
Copy link
Contributor

Fix set onCollapse and collapsed warning

before

warning(
    collapsed === undefined ||  onCollapse === undefined,
    'pro-layout: onCollapse and collapsed should exist simultaneously',
  );

after

warning(
    (collapsed === undefined) === (onCollapse === undefined),
    'pro-layout: onCollapse and collapsed should exist simultaneously',
  );

@@ -143,7 +143,7 @@ function useCollapsed(
onCollapse: BasicLayoutProps['onCollapse'],
): [boolean | undefined, BasicLayoutProps['onCollapse']] {
warning(
collapsed === undefined || onCollapse === undefined,
(collapsed === undefined) === (onCollapse === undefined),
Copy link
Collaborator

Choose a reason for hiding this comment

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

用 && 吧

Copy link
Contributor Author

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),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(collapsed === undefined) === (onCollapse === undefined),
(collapsed !== undefined && onCollapse !== undefined) || (collapsed === undefined && onCollapse === undefined)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

两种写法达到的目的是一致的,用===更精简点。

Copy link
Member

Choose a reason for hiding this comment

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

不一致,两个都不为 undefined 时也不应该 warning。

Copy link
Contributor Author

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。

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

要加个用例。

Copy link
Contributor Author

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)

这种写法更易读

Copy link
Member

Choose a reason for hiding this comment

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

可读性其实更重要一点。

@chenshuai2144
Copy link
Collaborator

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants