Skip to content

Commit

Permalink
feat: add hidden file (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Jan 20, 2022
1 parent 7e63511 commit 35b6f1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/editor/FileSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const pendingFilename = ref('Comp.vue')
const importMapFile = 'import-map.json'
const showImportMap = inject('import-map') as Ref<boolean>
const files = computed(() =>
Object.keys(store.state.files).filter((f) => f !== importMapFile)
Object.entries(store.state.files)
.filter(([name, file]) => name !== importMapFile && !file.hidden)
.map(([name]) => name)
)
function startAddFile() {
Expand Down
16 changes: 12 additions & 4 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ const msg = ref('Hello World!')
export class File {
filename: string
code: string
hidden: boolean
compiled = {
js: '',
css: '',
ssr: ''
}

constructor(filename: string, code = '') {
constructor(filename: string, code = '', hidden = false) {
this.filename = filename
this.code = code
this.hidden = hidden
}
}

Expand Down Expand Up @@ -129,9 +131,15 @@ export class ReplStore implements Store {
this.state.activeFile = this.state.files[filename]
}

addFile(filename: string) {
this.state.files[filename] = new File(filename)
this.setActive(filename)
addFile(filename: string): void
addFile(file: File): void
addFile(fileOrFilename: string | File): void {
const file =
typeof fileOrFilename === 'string'
? new File(fileOrFilename)
: fileOrFilename
this.state.files[file.filename] = file
if (!file.hidden) this.setActive(file.filename)
}

deleteFile(filename: string) {
Expand Down

0 comments on commit 35b6f1a

Please sign in to comment.