-
-
Notifications
You must be signed in to change notification settings - Fork 334
enhance: Lock switch field if needConfirm #892
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
Changes from 2 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,23 @@ | ||||||||||||||||||||||||||||||
| import * as React from 'react'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export default function useRangeActiveLock(): [ | ||||||||||||||||||||||||||||||
| focused: boolean, | ||||||||||||||||||||||||||||||
| triggerFocus: (focused: boolean) => void, | ||||||||||||||||||||||||||||||
| // lastOperation: (type?: OperationType) => OperationType, | ||||||||||||||||||||||||||||||
| // activeIndex: number, | ||||||||||||||||||||||||||||||
| setActiveIndex: (index: number) => void, | ||||||||||||||||||||||||||||||
| // nextActiveIndex: NextActive<DateType>, | ||||||||||||||||||||||||||||||
| // activeList: number[], | ||||||||||||||||||||||||||||||
| ] { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| export default function useRangeActiveLock(): [ | |
| focused: boolean, | |
| triggerFocus: (focused: boolean) => void, | |
| // lastOperation: (type?: OperationType) => OperationType, | |
| // activeIndex: number, | |
| setActiveIndex: (index: number) => void, | |
| // nextActiveIndex: NextActive<DateType>, | |
| // activeList: number[], | |
| ] { | |
| export default function useRangeActiveLock(): [ | |
| focused: boolean, | |
| triggerFocus: (focused: boolean) => void, | |
| setActiveIndex: (index: number) => void, | |
| ] { |
Outdated
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.
潜在的内存泄漏问题
activeList 数组只会不断增长而没有清理机制,可能导致内存泄漏。建议限制数组大小或在适当时机清理。
建议修改实现方式:
const onActive = (index: number) => {
setActiveIndex(index);
- setActiveList([...activeList, index]);
+ setActiveList(prevList => {
+ const newList = [...prevList, index];
+ // 只保留最近的 N 个记录
+ return newList.slice(-5);
+ });
};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const onActive = (index: number) => { | |
| setActiveIndex(index); | |
| setActiveList([...activeList, index]); | |
| }; | |
| const onActive = (index: number) => { | |
| setActiveIndex(index); | |
| setActiveList(prevList => { | |
| const newList = [...prevList, index]; | |
| // 只保留最近的 N 个记录 | |
| return newList.slice(-5); | |
| }); | |
| }; |
Outdated
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
返回值命名不一致
返回值中 setFocused 与类型定义中的 triggerFocus 命名不一致,onActive 与 setActiveIndex 命名不一致。
建议修改为:
- return [focused, setFocused, onActive];
+ return [focused, triggerFocus: setFocused, setActiveIndex: onActive];Committable suggestion skipped: line range outside the PR's diff.
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
建议删除注释代码而不是保留
建议完全删除这段被注释的代码,而不是将其保留在文件中。如果这些代码对于示例或测试很重要,应该:
保留注释掉的代码会: