From f4a0fe556865180b8cdae318fe1d253c48cf85b4 Mon Sep 17 00:00:00 2001 From: yetao Date: Thu, 31 Oct 2024 13:50:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor=F0=9F=8E=A8:=20=20(=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81)=EF=BC=9Astate..ts=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webview/src/view/state.ts | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/webview/src/view/state.ts b/webview/src/view/state.ts index 81f6fe3..98a558b 100644 --- a/webview/src/view/state.ts +++ b/webview/src/view/state.ts @@ -1,31 +1,76 @@ +// 导入 common/fileSystemConfig 模块中的 ConfigLocation 和 FileSystemConfig 类型 import type { ConfigLocation, FileSystemConfig } from 'common/fileSystemConfig'; +/** + * 定义一个视图状态接口,包含视图类型 + * @interface IViewState + * @template V - 视图类型,必须是字符串 + */ interface IViewState { + // 视图的类型 view: V; } +/** + * 定义开始屏幕状态接口,继承自 IViewState + * @interface IStartScreenState + * @extends IViewState<'startscreen'> + */ export interface IStartScreenState extends IViewState<'startscreen'> { + // 分组依据,默认为 'group' groupBy: string; } +/** + * 定义新配置状态接口,继承自 IViewState + * @interface INewConfigState + * @extends IViewState<'newconfig'> + */ export interface INewConfigState extends IViewState<'newconfig'> { + // 配置的位置,可选 location?: ConfigLocation; + // 配置的名称 name: string; } +/** + * 定义配置编辑器状态接口,继承自 IViewState + * @interface IConfigEditorState + * @extends IViewState<'configeditor'> + */ export interface IConfigEditorState extends IViewState<'configeditor'> { + // 旧的配置 oldConfig: FileSystemConfig; + // 新的配置 newConfig: FileSystemConfig; + // 状态消息,可选 statusMessage?: string; } +/** + * 定义配置定位器状态接口,继承自 IViewState + * @interface IConfigLocatorState + * @extends IViewState<'configlocator'> + */ export interface IConfigLocatorState extends IViewState<'configlocator'> { + // 配置列表 configs: FileSystemConfig[]; + // 搜索的配置名称 name: string; } +/** + * 定义一个状态类型,包含所有可能的视图状态 + * @type IState + * @description 状态类型,可能是开始屏幕、新配置、配置编辑器或配置定位器状态 + */ export type IState = IStartScreenState | INewConfigState | IConfigEditorState | IConfigLocatorState; +/** + * 默认状态,包含默认的分组依据和视图类型 + * @const DEFAULT_STATE + * @type {IState} + */ export const DEFAULT_STATE: IState = { groupBy: 'group', view: 'startscreen',