-
-
Notifications
You must be signed in to change notification settings - Fork 262
perf: refactor to avoid unnecessary re-render with mini-store #123
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
Conversation
src/MenuMixin.js
Outdated
| }, () => { | ||
| updateActiveKey(this.getStore(), this.getEventKey(), activeItem.props.eventKey); | ||
|
|
||
| /* TODO |
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.
@yesmeck how do we do setState callback?
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.
scrollIntoView 可以放到 componentDidUpdate 里。
callback(activeItem); 这句好像放在 callback 外也没影响。
| selectedKeys, | ||
| openKeys, | ||
| }; | ||
| activeKey: { '0-menu-': getActiveKey(props, props.activeKey) }, |
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.
activeKey 是不是只要数组就可以了?因为 key 是全局唯一的。
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.
key是全局唯一的,但是activeKey不是,每层都有一个,这样get操作也比较方便。
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.
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, |
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.
为什么 k 跟 eventKey 的类型会不一样?
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.
也是用 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, |
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.
用 indexOf 吧。
|
https://ant.design/components/menu/#components-menu-demo-sider-current 这个例子里,keyboard 的行为不一样了。 |
| {React.Children.map(props.children, this.renderMenuItem)} | ||
| {React.Children.map( | ||
| props.children, | ||
| (c, i, subIndex) => this.renderMenuItem(c, i, subIndex, props.eventKey || '0-menu-'), |
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.
subIndex 是 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.
subIndex是啥啊,我这部分code相当于没动,只是加了一个参数。我看下subIndex是啥
|
@yesmeck 恩 回头我看下 应该是小问题 |

Using mini store to subscribe local change to improve performance.
Before:

After:

Notes:
TODO items: