-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
enhance: Lock switch field if needConfirm #892
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[], | ||||||||||||||||||||||||||||||
] { | ||||||||||||||||||||||||||||||
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. 类型定义与实现不匹配 返回类型签名中包含了被注释掉的类型定义,这与实际实现的返回值不一致。建议移除未使用的类型定义或实现完整功能。 建议应用以下更改: export default function useRangeActiveLock(): [
focused: boolean,
triggerFocus: (focused: boolean) => void,
- // lastOperation: (type?: OperationType) => void,
- // activeIndex: number,
setActiveIndex: (index: number) => void,
- // nextActiveIndex: NextActive<DateType>,
- // activeList: number[],
] { 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
const [activeIndex, setActiveIndex] = React.useState<number | null>(null); | ||||||||||||||||||||||||||||||
const [focused, setFocused] = React.useState<boolean>(false); | ||||||||||||||||||||||||||||||
const [activeList, setActiveList] = React.useState<number[]>([]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// ============================= Active ============================= | ||||||||||||||||||||||||||||||
const onActive = (index: number) => { | ||||||||||||||||||||||||||||||
setActiveIndex(index); | ||||||||||||||||||||||||||||||
setActiveList([...activeList, index]); | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
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. 潜在的内存泄漏问题
建议修改实现方式: const onActive = (index: number) => {
setActiveIndex(index);
- setActiveList([...activeList, index]);
+ setActiveList(prevList => {
+ const newList = [...prevList, index];
+ // 只保留最近的 N 个记录
+ return newList.slice(-5);
+ });
}; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return [focused, setFocused, onActive]; | ||||||||||||||||||||||||||||||
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 返回值命名不一致 返回值中 建议修改为: - return [focused, setFocused, onActive];
+ return [focused, triggerFocus: setFocused, setActiveIndex: onActive];
|
||||||||||||||||||||||||||||||
} |
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
建议删除注释代码而不是保留
建议完全删除这段被注释的代码,而不是将其保留在文件中。如果这些代码对于示例或测试很重要,应该:
保留注释掉的代码会: