Skip to content

Commit 9e83b09

Browse files
committed
feat: mutable sfc options
1 parent 66013ac commit 9e83b09

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/Repl.vue

+19-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import SplitPane from './SplitPane.vue'
33
import Output from './output/Output.vue'
44
import { Store, ReplStore, SFCOptions } from './store'
5-
import { provide, ref, toRef, computed } from 'vue'
5+
import { provide, ref, toRef, computed, watchEffect } from 'vue'
66
import type { EditorComponentType } from './editor/types'
77
import EditorContainer from './editor/EditorContainer.vue'
88
@@ -56,29 +56,29 @@ if (!props.editor) {
5656
}
5757
5858
const outputRef = ref<InstanceType<typeof Output>>()
59-
const { store } = props
60-
const sfcOptions = (store.options = props.sfcOptions || {})
61-
if (!sfcOptions.script) {
62-
sfcOptions.script = {}
63-
}
64-
// @ts-ignore only needed in 3.3
65-
sfcOptions.script.fs = {
66-
fileExists(file: string) {
67-
if (file.startsWith('/')) file = file.slice(1)
68-
return !!store.state.files[file]
69-
},
70-
readFile(file: string) {
71-
if (file.startsWith('/')) file = file.slice(1)
72-
return store.state.files[file].code
73-
},
74-
}
7559
76-
store.init()
60+
watchEffect(() => {
61+
const { store } = props
62+
const sfcOptions = (store.options = props.sfcOptions || {})
63+
sfcOptions.script ||= {}
64+
sfcOptions.script.fs = {
65+
fileExists(file: string) {
66+
if (file.startsWith('/')) file = file.slice(1)
67+
return !!store.state.files[file]
68+
},
69+
readFile(file: string) {
70+
if (file.startsWith('/')) file = file.slice(1)
71+
return store.state.files[file].code
72+
},
73+
}
74+
})
75+
76+
props.store.init()
7777
7878
const editorSlotName = computed(() => (props.layoutReverse ? 'right' : 'left'))
7979
const outputSlotName = computed(() => (props.layoutReverse ? 'left' : 'right'))
8080
81-
provide('store', store)
81+
provide('store', props.store)
8282
provide('autoresize', props.autoResize)
8383
provide('import-map', toRef(props, 'showImportMap'))
8484
provide('tsconfig', toRef(props, 'showTsConfig'))

0 commit comments

Comments
 (0)