forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
import equal from 'fast-deep-equal'; | ||
import { type PersistOptions, devtools, persist } from 'zustand/middleware'; | ||
import { createWithEqualityFn } from 'zustand/traditional'; | ||
|
||
import { isDev } from '@/utils/env'; | ||
|
||
import { type SettingsStore, createStore } from './store'; | ||
|
||
export const LOBE_SETTINGS = 'LOBE_SETTINGS'; | ||
|
||
const persistOptions: PersistOptions<SettingsStore> = { | ||
name: LOBE_SETTINGS, | ||
skipHydration: true, | ||
}; | ||
|
||
export const useSettings = createWithEqualityFn<SettingsStore>()( | ||
persist( | ||
devtools(createStore, { | ||
name: LOBE_SETTINGS + (isDev ? '_DEV' : ''), | ||
}), | ||
persistOptions, | ||
), | ||
equal, | ||
); | ||
|
||
export * from './selectors'; | ||
export type { SettingsStore } from './store'; | ||
export { useSettings } from './store'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
import equal from 'fast-deep-equal'; | ||
import { PersistOptions, devtools, persist } from 'zustand/middleware'; | ||
import { createWithEqualityFn } from 'zustand/traditional'; | ||
import { StateCreator } from 'zustand/vanilla'; | ||
|
||
import { isDev } from '@/utils/env'; | ||
|
||
import { type AppSettingsState, initialState } from './initialState'; | ||
import { type AgentAction, createAgentSlice } from './slices/agent'; | ||
import { type CommonAction, createCommonSlice } from './slices/common'; | ||
|
||
// =============== 聚合 createStoreFn ============ // | ||
|
||
export type SettingsStore = CommonAction & AppSettingsState & AgentAction; | ||
|
||
export const createStore: StateCreator<SettingsStore, [['zustand/devtools', never]]> = ( | ||
const createStore: StateCreator<SettingsStore, [['zustand/devtools', never]]> = ( | ||
...parameters | ||
) => ({ | ||
...initialState, | ||
...createCommonSlice(...parameters), | ||
...createAgentSlice(...parameters), | ||
}); | ||
|
||
// =============== persist 本地缓存中间件配置 ============ // | ||
|
||
const LOBE_SETTINGS = 'LOBE_SETTINGS'; | ||
|
||
const persistOptions: PersistOptions<SettingsStore> = { | ||
name: LOBE_SETTINGS, | ||
skipHydration: true, | ||
}; | ||
|
||
// =============== 实装 useStore ============ // | ||
|
||
export const useSettings = createWithEqualityFn<SettingsStore>()( | ||
persist( | ||
devtools(createStore, { | ||
name: LOBE_SETTINGS + (isDev ? '_DEV' : ''), | ||
}), | ||
persistOptions, | ||
), | ||
equal, | ||
); |