-
Notifications
You must be signed in to change notification settings - Fork 161
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: avoid table jitter casued by changes in the first row #301
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export function debounce(fn: (...args) => void, delay: number = 300) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return function (...args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (timer) clearTimeout(timer); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
timer = setTimeout(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn.apply(this, args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
timer = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, delay); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 需要处理定时器清理以防止内存泄漏 当前的防抖函数实现可能会导致内存泄漏,因为定时器没有在适当的时候被清理。 建议按照以下方式重构代码: export function debounce(fn: (...args) => void, delay: number = 300) {
let timer;
- return function (...args) {
+ const debounced = function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
timer = null;
}, delay);
+ };
+
+ debounced.cancel = () => {
+ if (timer) {
+ clearTimeout(timer);
+ timer = null;
+ }
};
+
+ return debounced;
} 📝 Committable suggestion
Suggested change
|
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.
🛠️ Refactor suggestion
建议添加滚动状态重置的清理逻辑
在组件卸载时需要确保滚动状态被正确重置。