refactor: 收口推荐 runtime 自动启动
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# 【前端架构】Platform Recommend Runtime Auto Start 收口计划
|
||||
|
||||
## 背景
|
||||
|
||||
平台推荐页的 embedded runtime 会在移动端首页自动选择当前推荐作品并启动对应玩法。旧 `useEffect` 同时判断桌面断点、当前 stage、当前 Tab、平台 loading、推荐列表是否为空、active entry 是否仍存在、对应 runtime 是否 ready、是否已有启动请求,以及下一条 entry 应选谁。
|
||||
|
||||
这组判断是纯推荐流自动启动决策,但留在 `PlatformEntryFlowShellImpl.tsx` 会让 effect 依赖很长,也让后续新增玩法时容易把 ready 判定和启动时机混在副作用里。
|
||||
|
||||
## 决策
|
||||
|
||||
扩展 `src/components/platform-entry/platformPublicGalleryFlow.ts`,新增 `resolvePlatformRecommendRuntimeAutoStartDecision(input)`:
|
||||
|
||||
- `noop`:当前不需要改变推荐 runtime。
|
||||
- `clear`:推荐列表为空,壳层应清空 active entry、runtime kind 和错误。
|
||||
- `start`:壳层应调用既有 `selectRecommendRuntimeEntry(entry)` 启动指定作品。
|
||||
|
||||
`PlatformEntryFlowShellImpl.tsx` 继续作为 **Adapter**:它负责收集 React state、清空 state、调用 `selectRecommendRuntimeEntry(...)` 和执行各玩法 runtime 副作用。
|
||||
|
||||
## Interface 约束
|
||||
|
||||
- 桌面端、非 `platform` stage、非 `home` Tab 或平台仍在 loading 时返回 `noop`。
|
||||
- 推荐列表为空时返回 `clear`。
|
||||
- active entry 存在且对应 runtime 已 ready 时返回 `noop`。
|
||||
- 当前已有启动请求时返回 `noop`。
|
||||
- active entry 存在但未 ready 时返回 `start(activeEntry)`。
|
||||
- active key 缺失或已不在列表中时返回 `start(firstEntry)`。
|
||||
|
||||
## Depth / Leverage / Locality
|
||||
|
||||
- **Depth**:壳层只消费三态决策;列表查找、ready 判定和自动启动门禁藏入 Flow Module Implementation。
|
||||
- **Leverage**:后续推荐流新增玩法或改 ready 判定,只需补 `platformPublicGalleryFlow.ts` 的模型测试。
|
||||
- **Locality**:effect 只保留副作用动作,不再承载推荐流状态机知识。
|
||||
|
||||
## 验收
|
||||
|
||||
- `npm run test -- src/components/platform-entry/platformPublicGalleryFlow.test.ts`
|
||||
- `npx eslint --max-warnings 0 src/components/platform-entry/platformPublicGalleryFlow.ts src/components/platform-entry/platformPublicGalleryFlow.test.ts`
|
||||
- `npx eslint src/components/platform-entry/PlatformEntryFlowShellImpl.tsx --quiet`
|
||||
- `npm run typecheck`
|
||||
- `npm run check:encoding`
|
||||
Reference in New Issue
Block a user