Download packages/@core/base/shared/src/global-state.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/%40core/base/shared/src/global-state.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/packages/@core/base/shared/src/global-state.ts
-
curl -L -o global-state.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/packages/%40core/base/shared/src/global-state.ts
1.07 kB
| /** | |
| * 全局复用的变量、组件、配置,各个模块之间共享 | |
| * 通过单例模式实现,单例必须注意不受请求影响,例如用户信息这些需要根据请求获取的。后续如果有ssr需求,也不会影响 | |
| */ | |
| interface ComponentsState { | |
| [key: string]: any; | |
| } | |
| interface MessageState { | |
| copyPreferencesSuccess?: (title: string, content?: string) => void; | |
| } | |
| export interface IGlobalSharedState { | |
| components: ComponentsState; | |
| message: MessageState; | |
| } | |
| class GlobalShareState { | |
| #components: ComponentsState = {}; | |
| #message: MessageState = {}; | |
| /** | |
| * 定义框架内部各个场景的消息提示 | |
| */ | |
| public defineMessage({ copyPreferencesSuccess }: MessageState) { | |
| this.#message = { | |
| copyPreferencesSuccess, | |
| }; | |
| } | |
| public getComponents(): ComponentsState { | |
| return this.#components; | |
| } | |
| public getMessage(): MessageState { | |
| return this.#message; | |
| } | |
| public setComponents(value: ComponentsState) { | |
| this.#components = value; | |
| } | |
| } | |
| export const globalShareState = new GlobalShareState(); | |