Svelte refactoring ok

This commit is contained in:
Simon Cambier
2022-04-16 17:24:04 +02:00
parent 40aba85729
commit 832e782ba8
9 changed files with 300 additions and 230 deletions

View File

@@ -1,12 +1,33 @@
import { get, writable } from 'svelte/store'
import type { ResultNote } from './globals'
import type { IndexedNote, ResultNote } from './globals'
import type OmnisearchPlugin from './main'
import type { OmnisearchModal } from './modal'
// export const selectedNoteId = writable<string>('')
export const searchQuery = writable<string>('')
export const resultNotes = writable<ResultNote[]>([])
function createIndexedNotes() {
const { subscribe, set, update } = writable<Record<string, IndexedNote>>({})
return {
subscribe,
set,
add(note: IndexedNote) {
update(notes => {
notes[note.path] = note
return notes
})
},
remove(path: string) {
update(notes => {
delete notes[path]
return notes
})
},
get(path: string): IndexedNote | undefined {
return get(indexedNotes)[path]
},
}
}
function createSelectedNote() {
const { subscribe, set, update } = writable<ResultNote|null>(null)
const { subscribe, set, update } = writable<ResultNote | null>(null)
return {
subscribe,
set,
@@ -31,4 +52,9 @@ function createSelectedNote() {
}
}
export const searchQuery = writable<string>('')
export const resultNotes = writable<ResultNote[]>([])
export const plugin = writable<OmnisearchPlugin>()
export const modal = writable<OmnisearchModal>()
export const selectedNote = createSelectedNote()
export const indexedNotes = createIndexedNotes()