Skip to content

Commit 31ecf50

Browse files
committed
feat(Preview): add update-preview event
1 parent 7013e56 commit 31ecf50

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/output/Preview.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import { Store, importMapFile } from '../store'
1717
import { Props } from '../Repl.vue'
1818
1919
const props = defineProps<{ show: boolean; ssr: boolean }>()
20+
export type UpdateFlag = 'UPDATING' | 'SUCCESS' | 'FAILURE'
21+
const emits = defineEmits<{
22+
(e: 'update-preview', flag: UpdateFlag): UpdateFlag
23+
}>()
2024
2125
const store = inject('store') as Store
2226
const clearConsole = inject('clear-console') as Ref<boolean>
@@ -160,6 +164,7 @@ function createSandbox() {
160164
}
161165
162166
async function updatePreview() {
167+
emits('update-preview', 'UPDATING')
163168
if (import.meta.env.PROD && clearConsole.value) {
164169
console.clear()
165170
}
@@ -260,8 +265,10 @@ async function updatePreview() {
260265
261266
// eval code in sandbox
262267
await proxy.eval(codeToEval)
268+
emits('update-preview', 'SUCCESS')
263269
} catch (e: any) {
264270
runtimeError.value = (e as Error).message
271+
emits('update-preview', 'FAILURE')
265272
}
266273
}
267274
</script>

0 commit comments

Comments
 (0)