refactor: 收口作品架 Source Adapter registry

This commit is contained in:
2026-06-03 15:47:26 +08:00
parent cf0840d9e9
commit 5783bfeea6
4 changed files with 225 additions and 72 deletions

View File

@@ -8,16 +8,18 @@
`CreationWorkShelfItem.actions.open` 是打开作品的正式 **Interface**`CustomWorldCreationHub.tsx` 只负责卡片点击与 `onOpenShelfItem` 通知,然后调用 `item.actions.open()`,不再根据 `item.source.kind` 分发玩法。
`buildCreationWorkShelfItemsFromSources` 是作品架 source registry 的正式 **Interface**。每个玩法提供一个 `CreationWorkShelfSourceAdapter`Adapter 负责把玩法数据、删除权限、打开动作和特殊动作映射为 `CreationWorkShelfItem[]`。registry 统一执行 flatten、运行态覆盖、持久化生成态兜底和更新时间排序。
此决策让 `creationWorkShelf.ts`**Module** 更 deep
- **Implementation**:玩法差异、草稿 / 已发布分支、profileId 进入方式和回调绑定都留在 Work Shelf Adapter 内。
- **Interface**Hub 只需要 `CreationWorkShelfItem`,不需要知道每种玩法的打开规则。
- **Interface**Hub 只需要 `CreationWorkShelfItem`;后续调用方也可只传 `CreationWorkShelfSourceAdapter[]`,不需要知道每种玩法的打开规则、状态覆盖和排序规则
- **Leverage**:新增玩法时只补 shelf item 映射与 AdapterHub 不再新增 switch 分支。
- **Locality**:作品架点击行为错误集中在 `creationWorkShelf.ts` 与其测试里定位。
- **Locality**:作品架点击行为、source flatten、运行态覆盖和排序错误集中在 `creationWorkShelf.ts` 与其测试里定位。
## 后续深化
下一步可把 `buildCreationWorkShelfItems` 当前的长参数列表继续收口为 per-kind Source Adapter registry。届时 Hub / 平台壳传入玩法数据源和回调时,可逐步减少按玩法平铺的参数数量。删除、刷新和直达恢复也可沿同一 seam 收口。
`buildCreationWorkShelfItems` 仍保留旧长参数兼容入口,但其 **Implementation** 已改为组装 `CreationWorkShelfSourceAdapter[]` 后复用 `buildCreationWorkShelfItemsFromSources`。下一步可让 Hub / 平台壳逐步直接传入 source adapters从而减少按玩法平铺的参数数量。删除、刷新和直达恢复也可沿同一 seam 收口。
## 验证