refactor(sidebar): move SidebarPage/BottomNavItem enums to sidebar-state

Move the `SidebarPage` and `BottomNavItem` enum definitions from
`sidebar-machine.ts` to `sidebar-state.ts` to avoid a circular
dependency between the two modules. Since both enums are tightly
coupled to the state shape (they define the value sets of
`currentPage` and `selectedBottomNavItem`), they now live alongside
the state itself.

- Move enum declarations and types from `sidebar-machine.ts` to
  `sidebar-state.ts`
- Update `sidebar-events.ts` import path to reference `sidebar-state`
- Keep `sidebar-machine.ts` re-exporting `SidebarState` and
  `initialState` to preserve its public API
This commit is contained in:
2026-06-11 10:35:57 +08:00
parent d0df7296cc
commit 39ef78e9ea
3 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
/** /**
* Sidebar 状态机:事件联合 * Sidebar 状态机:事件联合
*/ */
import type { SidebarPage, BottomNavItem } from "./sidebar-machine"; import type { SidebarPage, BottomNavItem } from "./sidebar-state";
export type SidebarEvent = export type SidebarEvent =
| { | {
+1 -23
View File
@@ -11,31 +11,9 @@
*/ */
import { setup, assign } from "xstate"; import { setup, assign } from "xstate";
import { SidebarState, initialState } from "./sidebar-state"; import { BottomNavItem, SidebarState, initialState } from "./sidebar-state";
import type { SidebarEvent } from "./sidebar-events"; import type { SidebarEvent } from "./sidebar-events";
/**
* Sidebar 页面/底部导航枚举(与原 sidebar-types.ts 保持一致)
*/
export const SidebarPage = {
DefaultView: "defaultView",
Profile: "profile",
Topics: "topics",
Gifts: "gifts",
Activities: "activities",
} as const;
export type SidebarPage = (typeof SidebarPage)[keyof typeof SidebarPage];
export const BottomNavItem = {
None: "none",
Topics: "topics",
Gifts: "gifts",
Activities: "activities",
} as const;
export type BottomNavItem = (typeof BottomNavItem)[keyof typeof BottomNavItem];
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变 // 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
export type { SidebarState } from "./sidebar-state"; export type { SidebarState } from "./sidebar-state";
export { initialState } from "./sidebar-state"; export { initialState } from "./sidebar-state";
+24 -2
View File
@@ -1,9 +1,31 @@
/** /**
* Sidebar 状态机:State 形状 + 初始值 * Sidebar 状态机:State 形状 + 初始值
* *
* SidebarPage / BottomNavItem 仍由 sidebar-machine.ts 导出(事件/上下文均需引用)。 * 枚举 `SidebarPage` / `BottomNavItem` 与 state 形状强相关(`currentPage` /
* `selectedBottomNavItem` 字段的取值集合),因此与 state 同源定义在本文件,
* 避免与 `sidebar-machine.ts` 形成循环引用。
*/ */
import { SidebarPage, BottomNavItem } from "./sidebar-machine";
/** 页面枚举(侧边栏主区域可显示的页面) */
export const SidebarPage = {
DefaultView: "defaultView",
Profile: "profile",
Topics: "topics",
Gifts: "gifts",
Activities: "activities",
} as const;
export type SidebarPage = (typeof SidebarPage)[keyof typeof SidebarPage];
/** 底部导航枚举(选中态) */
export const BottomNavItem = {
None: "none",
Topics: "topics",
Gifts: "gifts",
Activities: "activities",
} as const;
export type BottomNavItem = (typeof BottomNavItem)[keyof typeof BottomNavItem];
export interface SidebarState { export interface SidebarState {
currentPage: SidebarPage; currentPage: SidebarPage;