mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 15:40:10 +00:00
[fix] Improve type safety in keybinding migration
Replace 'any' type with proper 'Keybinding[]' type annotation in the keybinding migration. Also create new objects during migration to avoid mutating the original keybinding data, which follows immutability best practices and prevents potential side effects. This ensures better type checking and makes the migration code more robust and maintainable.
This commit is contained in:
@@ -40,13 +40,18 @@ export const SETTING_MIGRATIONS: SettingMigration[] = [
|
||||
const settingStore = useSettingStore()
|
||||
const keybindings = settingStore.get(
|
||||
'Comfy.Keybinding.UnsetBindings'
|
||||
) as any[]
|
||||
) as Keybinding[]
|
||||
const migrated = keybindings.map((keybinding) => {
|
||||
if (keybinding['targetSelector'] === '#graph-canvas') {
|
||||
keybinding['targetElementId'] = 'graph-canvas'
|
||||
delete keybinding['targetSelector']
|
||||
// Create a new object to avoid mutating the original
|
||||
const newKeybinding = { ...keybinding }
|
||||
if (
|
||||
'targetSelector' in newKeybinding &&
|
||||
newKeybinding['targetSelector'] === '#graph-canvas'
|
||||
) {
|
||||
newKeybinding['targetElementId'] = 'graph-canvas'
|
||||
delete newKeybinding['targetSelector']
|
||||
}
|
||||
return keybinding
|
||||
return newKeybinding
|
||||
})
|
||||
await settingStore.set('Comfy.Keybinding.UnsetBindings', migrated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user