update: store persist
This commit is contained in:
@@ -1,24 +1,41 @@
|
||||
import { create } from 'zustand'
|
||||
import { tauriStore } from '@/utils/persist'
|
||||
import { createJSONStorage, persist } from 'zustand/middleware'
|
||||
|
||||
|
||||
interface AppState {
|
||||
version: number
|
||||
version: string
|
||||
hasUpdate: boolean
|
||||
hasInit: boolean
|
||||
notice: string
|
||||
useMirror: boolean
|
||||
setVersion: (version: string) => void
|
||||
init: () => void
|
||||
}
|
||||
|
||||
const useAppStore = create<AppState>()((/* set */) => ({
|
||||
version: 0,
|
||||
hasUpdate: false,
|
||||
hasInit: false,
|
||||
notice: "",
|
||||
useMirror: true,
|
||||
init: () => {
|
||||
console.log('init')
|
||||
},
|
||||
// increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
|
||||
}))
|
||||
const { /* store, */storage } = tauriStore("app-test")
|
||||
|
||||
const useAppStore = create<AppState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
version: "0.0.1",
|
||||
hasUpdate: false,
|
||||
hasInit: false,
|
||||
notice: "Man! What can I say?",
|
||||
useMirror: true,
|
||||
setVersion: (version: string) => set(() => ({ version: version })),
|
||||
init: () => {
|
||||
console.log('init')
|
||||
console.log(get().version)
|
||||
// const version = await store.get("version")
|
||||
// set(() => ({ version: version }))
|
||||
},
|
||||
// increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
|
||||
}),
|
||||
{
|
||||
name: 'app', // name of item in the storage (must be unique)
|
||||
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
|
||||
},
|
||||
))
|
||||
|
||||
export default useAppStore
|
||||
Reference in New Issue
Block a user