feat: add state management using zustand
This commit is contained in:
18
src/store/index.ts
Normal file
18
src/store/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createStore } from 'zustand'
|
||||
import { subscribeWithSelector } from 'zustand/middleware'
|
||||
import { MODULE_NAME } from '@/constants'
|
||||
import { type ConfigSlice, createConfigSlice } from '@/store/configSlice'
|
||||
|
||||
export const useStore = createStore<ConfigSlice>()(
|
||||
subscribeWithSelector(createConfigSlice)
|
||||
)
|
||||
|
||||
useStore.subscribe(
|
||||
(state) => state.wordLists,
|
||||
(wordLists) => {
|
||||
const context = SillyTavern.getContext()
|
||||
// biome-ignore lint/suspicious/noExplicitAny: SillyTavern's extensionSettings is not properly typed
|
||||
const extensionSettings: Record<string, any> = context.extensionSettings
|
||||
extensionSettings[MODULE_NAME] = { wordLists }
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user