fix: cleanup command when hot reload

zio/stable
三咲智子 2022-12-01 21:52:40 +08:00
parent 17a15e2917
commit 335fc9f64b
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
1 changed files with 9 additions and 5 deletions

View File

@ -175,9 +175,10 @@ export const useCommand = (cmd: CommandProvider) => {
registry.register(cmd)
onDeactivated(() => {
registry.remove(cmd)
})
const cleanup = () => registry.remove(cmd)
onDeactivated(cleanup)
tryOnScopeDispose(cleanup)
}
export const useCommands = (cmds: () => CommandProvider[]) => {
@ -192,9 +193,12 @@ export const useCommands = (cmds: () => CommandProvider[]) => {
registry.register(cmd)
}, { deep: true, immediate: true })
onDeactivated(() => {
const cleanup = () => {
commands.value.forEach(cmd => registry.remove(cmd))
})
}
onDeactivated(cleanup)
tryOnScopeDispose(cleanup)
}
export const provideGlobalCommands = () => {