tui: rename kvStore to store for consistency
This commit is contained in:
@@ -8,13 +8,13 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
|
|||||||
name: "KV",
|
name: "KV",
|
||||||
init: () => {
|
init: () => {
|
||||||
const [ready, setReady] = createSignal(false)
|
const [ready, setReady] = createSignal(false)
|
||||||
const [kvStore, setKvStore] = createStore<Record<string, any>>()
|
const [store, setStore] = createStore<Record<string, any>>()
|
||||||
const file = Bun.file(path.join(Global.Path.state, "kv.json"))
|
const file = Bun.file(path.join(Global.Path.state, "kv.json"))
|
||||||
|
|
||||||
file
|
file
|
||||||
.json()
|
.json()
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
setKvStore(x)
|
setStore(x)
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@@ -26,10 +26,10 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
|
|||||||
return ready()
|
return ready()
|
||||||
},
|
},
|
||||||
get store() {
|
get store() {
|
||||||
return kvStore
|
return store
|
||||||
},
|
},
|
||||||
signal<T>(name: string, defaultValue: T) {
|
signal<T>(name: string, defaultValue: T) {
|
||||||
if (kvStore[name] === undefined) setKvStore(name, defaultValue)
|
if (store[name] === undefined) setStore(name, defaultValue)
|
||||||
return [
|
return [
|
||||||
function () {
|
function () {
|
||||||
return result.get(name)
|
return result.get(name)
|
||||||
@@ -40,11 +40,11 @@ export const { use: useKV, provider: KVProvider } = createSimpleContext({
|
|||||||
] as const
|
] as const
|
||||||
},
|
},
|
||||||
get(key: string, defaultValue?: any) {
|
get(key: string, defaultValue?: any) {
|
||||||
return kvStore[key] ?? defaultValue
|
return store[key] ?? defaultValue
|
||||||
},
|
},
|
||||||
set(key: string, value: any) {
|
set(key: string, value: any) {
|
||||||
setKvStore(key, value)
|
setStore(key, value)
|
||||||
Bun.write(file, JSON.stringify(kvStore, null, 2))
|
Bun.write(file, JSON.stringify(store, null, 2))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user