refactor: 收口生成进度 tick 判定

This commit is contained in:
2026-06-04 02:49:23 +08:00
parent 80dab35646
commit 5dd73186b0
7 changed files with 320 additions and 25 deletions

View File

@@ -0,0 +1,37 @@
# 【前端架构】Platform Generation Progress Tick Model 收口计划
## 背景
`PlatformEntryFlowShellImpl.tsx` 的生成页进度 tick effect 曾以内联三元链按 `selectionStage` 选择拼图、抓大鹅、大鱼吃小鱼、方洞挑战、跳一跳、敲木鱼和宝贝识物的生成状态,并额外手写视觉小说的 `startedAtMs` / `phase` 判定。壳层因此既要维护 `setInterval` 副作用,又要记住每个生成页 stage 对应哪份进度状态。
生成进度是否需要 tick 是纯判定;`Date.now()``window.setInterval` 和进度时间 state 写入仍属于 React 壳层副作用。
## 决策
新增 `src/components/platform-entry/platformGenerationProgressTickModel.ts` 作为 Platform Generation Progress Tick **Module**。其公开 **Interface** 为:
- `resolvePlatformGenerationProgressTickDecision(input)`:输入当前 `selectionStage`、各小游戏 `MiniGameDraftGenerationState` 和视觉小说轻量生成状态,输出 `{ activeKind, shouldTick }`
- `PlatformGenerationProgressTickKind`:枚举可 tick 的生成类型,包含已有小游戏生成 kind 与 `visual-novel`
`PlatformEntryFlowShellImpl.tsx` 仍作为 **Adapter**:它把当前 state 组装给 Module`shouldTick=false` 则不启动 interval若为真仍按旧逻辑立即写一次 `Date.now()`,再每 `500ms` 更新并在 effect cleanup 中清理 timer。
## Interface 约束
- 小游戏生成 stage 只读取匹配 kind 的 `MiniGameDraftGenerationState`stage 与 state 不匹配时不 tick。
- 小游戏状态缺失、`phase='ready'``phase='failed'` 时不 tick其它 phase 按进行中处理。
- `visual-novel-generating` 不强行转成 `MiniGameDraftGenerationState`,只在 `startedAtMs != null` 且 phase 非 `ready` / `failed` 时 tick。
- 非生成 stage 即使传入可运行 state 也不 tick。
- 本 Module 不计算进度、不重建 view state、不处理拼图 / 抓大鹅 background task 覆盖;这些仍按既有生成页和作品架模型处理。
## Depth / Leverage / Locality
- **Depth**:壳层只消费 `shouldTick`stage 到 state 的映射和终态判定藏入 Module Implementation。
- **Leverage**:新增生成页玩法时,先扩展 stage-to-kind 映射和单测,再让壳层 Adapter 传入对应 state。
- **Locality**:生成进度 tick 规则集中到一个纯测试面interval 副作用继续局部留在 React effect避免把 timer 控制做成浅 Interface。
## 验收
- `npm run test -- src/components/platform-entry/platformGenerationProgressTickModel.test.ts`
- `npx eslint src/components/platform-entry/platformGenerationProgressTickModel.ts src/components/platform-entry/platformGenerationProgressTickModel.test.ts src/components/platform-entry/PlatformEntryFlowShellImpl.tsx --quiet`
- `npm run typecheck`
- `npm run check:encoding`