Skip to content
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

Merged
merged 6 commits into from
Apr 17, 2024
Merged

fix: add width caculate #120

merged 6 commits into from
Apr 17, 2024

Conversation

zhbyak
Copy link

@zhbyak zhbyak commented Apr 16, 2024

No description provided.

Comment on lines 39 to 42
useGlobalStore.setState({
drawerWidth: caculateDrawerWidth(),
backWidth: caculateBackWidth(),
});

Choose a reason for hiding this comment

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

为啥要定时去算宽度来着

Copy link
Author

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秒。其次是还有很多时候用户切换到其他页面等等因素,这两个时机是不够的,因此加入到全局的计算中去。定时计算宽度,如果宽度不变,我认为性能损耗是不高的。

Copy link

@huangbinjie huangbinjie Apr 17, 2024

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 够用了,长点的话插件有最小宽度保底问题不大

Comment on lines 27 to 28
drawerWidth: number;
backWidth: number;

Choose a reason for hiding this comment

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

emmm,看起来宽度没必要 lift 到全局把

Copy link
Author

Choose a reason for hiding this comment

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

主要是想把定时任务的代码都收拢到/content/index.ts中去方便管理。然后宽度这个东西勉强算个全局变量吧,描述的是整体的宽度

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

Copy link
Author

Choose a reason for hiding this comment

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

好的 放到drawer/index.tsx

Copy link

@huangbinjie huangbinjie left a comment

Choose a reason for hiding this comment

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

lgtm

@zhbyak zhbyak merged commit 9c16cfb into main Apr 17, 2024
2 checks passed
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.

2 participants