UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

37 lines (29 loc) 1.28 kB
import { subscribeWithSelector } from 'zustand/middleware'; import { shallow } from 'zustand/shallow'; import { createWithEqualityFn } from 'zustand/traditional'; import { StateCreator } from 'zustand/vanilla'; import { createDevtools } from '../middleware/createDevtools'; import { type GlobalClientDBAction, clientDBSlice } from './actions/clientDb'; import { type GlobalGeneralAction, generalActionSlice } from './actions/general'; import { type GlobalWorkspacePaneAction, globalWorkspaceSlice } from './actions/workspacePane'; import { type GlobalState, initialState } from './initialState'; // =============== 聚合 createStoreFn ============ // export interface GlobalStore extends GlobalState, GlobalWorkspacePaneAction, GlobalClientDBAction, GlobalGeneralAction { /* empty */ } const createStore: StateCreator<GlobalStore, [['zustand/devtools', never]]> = (...parameters) => ({ ...initialState, ...globalWorkspaceSlice(...parameters), ...clientDBSlice(...parameters), ...generalActionSlice(...parameters), }); // =============== 实装 useStore ============ // const devtools = createDevtools('global'); export const useGlobalStore = createWithEqualityFn<GlobalStore>()( subscribeWithSelector(devtools(createStore)), shallow, );