-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kit): unregister app instance when instance is unmounted (#340)
- Loading branch information
1 parent
19a716c
commit 5da5a6c
Showing
11 changed files
with
87 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { apiHooks } from './hook' | ||
import { instanceHooks } from './hook' | ||
|
||
export function remove() { | ||
apiHooks.removeAllHooks() | ||
instanceHooks.forEach(unregister => unregister()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script setup lang="ts"> | ||
import { App, createApp, shallowRef, triggerRef } from 'vue' | ||
import Foo from './Foo.vue' | ||
const dynamicInstance = shallowRef<App | null>(null) | ||
function registerApp() { | ||
const app = createApp(Foo) | ||
app.mount('#dynamic-app') | ||
dynamicInstance.value = app | ||
triggerRef(dynamicInstance) | ||
} | ||
function removeApp() { | ||
if (!dynamicInstance.value) | ||
return | ||
dynamicInstance.value.unmount() | ||
document.querySelector('#dynamic-app')!.innerHTML = '' | ||
dynamicInstance.value = null | ||
triggerRef(dynamicInstance) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<button v-if="!dynamicInstance" @click="registerApp"> | ||
Register App | ||
</button> | ||
<button v-if="dynamicInstance" @click="removeApp"> | ||
Remove App | ||
</button> | ||
<div id="dynamic-app" /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<script setup lang="ts"> | ||
const text = ref('Foo') | ||
</script> | ||
|
||
<template> | ||
<div> | ||
Foo Component | ||
{{ text }} Component | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters