Skip to content

Conversation

@picodoth
Copy link
Contributor

Using mini store to subscribe local change to improve performance.

Before:
before

After:
after

Notes:

  1. Every menu and subMenu have to keep their own entrance in mini store for both activeKey and defaultActiveFirst configuration.
  2. All unit tests passed and verified carefully that all behaviors are identical to previous version.

TODO items:

  1. We wanted to get rid of mixin once for all, but it was too big change to go with this one. Not confident enough to do that refactor yet...
  2. Mini Store does not support setState callbacks, might need some help. But it should be a very minor thing.

@picodoth picodoth requested review from afc163 and yesmeck March 14, 2018 14:50
src/MenuMixin.js Outdated
}, () => {
updateActiveKey(this.getStore(), this.getEventKey(), activeItem.props.eventKey);

/* TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yesmeck how do we do setState callback?

Copy link
Member

Choose a reason for hiding this comment

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

scrollIntoView 可以放到 componentDidUpdate 里。

callback(activeItem); 这句好像放在 callback 外也没影响。

@coveralls
Copy link

coveralls commented Mar 14, 2018

Coverage Status

Coverage increased (+0.3%) to 84.961% when pulling b5d2f72 on perf-improve into d9a414f on master.

@picodoth picodoth self-assigned this Mar 16, 2018
selectedKeys,
openKeys,
};
activeKey: { '0-menu-': getActiveKey(props, props.activeKey) },
Copy link
Member

Choose a reason for hiding this comment

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

activeKey 是不是只要数组就可以了?因为 key 是全局唯一的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

key是全局唯一的,但是activeKey不是,每层都有一个,这样get操作也比较方便。

Copy link
Member

@yesmeck yesmeck Mar 19, 2018

Choose a reason for hiding this comment

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

activeKey 应该是跟 openKeys 类似的。里面包含的 key 是唯一的。

src/SubMenu.jsx Outdated
export default SubMenu;
export default connect(({ openKeys, activeKey }, { eventKey }) => ({
// k is of type integer, and eventKey is of type string
isOpen: openKeys.findIndex((k) => k === eventKey) > -1,
Copy link
Member

Choose a reason for hiding this comment

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

为什么 keventKey 的类型会不一样?

Copy link
Member

Choose a reason for hiding this comment

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

也是用 indexOf

src/MenuItem.jsx Outdated
export default MenuItem;
export default connect(({ activeKey, selectedKeys }, { eventKey }) => ({
active: activeKey[getMenuIdFromItemEventKey(eventKey)] === eventKey,
isSelected: selectedKeys.findIndex((k) => k === eventKey) !== -1,
Copy link
Member

Choose a reason for hiding this comment

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

indexOf 吧。

@yesmeck
Copy link
Member

yesmeck commented Mar 20, 2018

https://ant.design/components/menu/#components-menu-demo-sider-current

这个例子里,keyboard 的行为不一样了。

@picodoth
Copy link
Contributor Author

picodoth commented Mar 27, 2018

@yesmeck b5d2f72 fixed the problem :(

{React.Children.map(props.children, this.renderMenuItem)}
{React.Children.map(
props.children,
(c, i, subIndex) => this.renderMenuItem(c, i, subIndex, props.eventKey || '0-menu-'),
Copy link
Member

Choose a reason for hiding this comment

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

subIndex 是 undefined ?

Copy link
Contributor Author

@picodoth picodoth Mar 28, 2018

Choose a reason for hiding this comment

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

subIndex是啥啊,我这部分code相当于没动,只是加了一个参数。我看下subIndex是啥

@yesmeck yesmeck merged commit 018d6f8 into master Mar 28, 2018
@yesmeck yesmeck deleted the perf-improve branch March 28, 2018 06:52
@yesmeck
Copy link
Member

yesmeck commented Mar 28, 2018

有个新问题, hover 子菜单标题的时候会 active 第一个 menu item。

kapture 2018-03-28 at 15 37 09

@picodoth
Copy link
Contributor Author

@yesmeck 恩 回头我看下 应该是小问题

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