-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix: add width caculate #120
Conversation
# Conflicts: # src/store/useGlobalStore.ts
src/content/index.tsx
Outdated
useGlobalStore.setState({ | ||
drawerWidth: caculateDrawerWidth(), | ||
backWidth: caculateBackWidth(), | ||
}); |
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.
之前的计算频率是在onload onresize两个事件触发的时候进行计算。但是onresize不会经常被触发,除非用户手动调整窗口。onload要基于twitter全部加载完成,有时候时间很长,要30秒。其次是还有很多时候用户切换到其他页面等等因素,这两个时机是不够的,因此加入到全局的计算中去。定时计算宽度,如果宽度不变,我认为性能损耗是不高的。
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.
我测试了下,宽度不变定时去 set 也会导致 rerender。而且因为是根节点和到处都用的全局 store,导致整个插件定时的 rerender。感觉 onLoad 够用了,长点的话插件有最小宽度保底问题不大
src/store/useGlobalStore.ts
Outdated
drawerWidth: number; | ||
backWidth: number; |
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.
emmm,看起来宽度没必要 lift 到全局把
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.
主要是想把定时任务的代码都收拢到/content/index.ts中去方便管理。然后宽度这个东西勉强算个全局变量吧,描述的是整体的宽度
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.
你放到 drawer/index.tsx
里面更适合,不然你定时去 setInterval 会导致所有组件都会定时去 rerender
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.
好的 放到drawer/index.tsx
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.
lgtm
No description provided.