refactor: 收口推荐滑动卡模型

This commit is contained in:
2026-06-03 21:11:13 +08:00
parent 30ead590e2
commit c238ef9b40
6 changed files with 248 additions and 24 deletions

View File

@@ -0,0 +1,42 @@
# RecommendSwipeDeckModel 收口计划
## 背景
移动端推荐首页的纵向 swipe deck 曾把拖拽阈值、offset clamp、commit 方向、rail class 和分享文案直接放在 `RpgEntryHomeView.tsx` Implementation 内。页面因此同时理解 DOM pointer 副作用、动画副作用与推荐卡纯规则,后续调整手势阈值或分享文案时缺少稳定测试面。
## 决策
- 新增 `src/components/rpg-entry/rpgEntryRecommendSwipeDeckModel.ts` 作为 Recommend Swipe Deck Module。
- Module Interface 收口:
- `hasRecommendDragStarted`
- `clampRecommendDragOffset`
- `resolveRecommendDragCommitDirection`
- `resolveRecommendCommitOffset`
- `buildRecommendSwipeRailClassName`
- `shouldAnimateRecommendSwipe`
- `buildRecommendShareText`
- `RpgEntryHomeView.tsx` 保留 pointer capture、DOM 高度读取、`setTimeout`、clipboard、like/remix/open 等副作用 Adapter推荐卡纯规则不再散落在页面 Implementation 内。
## Interface 约束
- swipe 阈值、commit 动画时长和 drag fallback limit 只从 Module 导出,不在页面重复定义。
- `deltaY < 0` 表示上滑进入下一条,返回方向 `1``deltaY > 0` 表示下滑进入上一条,返回方向 `-1`
- 未达到 commit 阈值时必须返回 `null`,页面 Adapter 只负责把 offset 归零。
- rail class 仅由 `offsetY``commitDirection` 决定CSS class 名保持现有命名。
- 分享文案只使用公开作品名、作品号和详情 URL公开作品码解析与复制副作用仍在页面 Adapter。
## Depth / Leverage / Locality
- **Depth**:页面传入少量数值或公开作品身份,即可得到拖拽状态、提交方向、动画 class 和分享文案。
- **Leverage**:调整推荐 swipe 体验时只需改 Module 与单测,交互测试仍护页面 Adapter。
- **Locality**pointer 事件生命周期与纯规则分离,推荐卡手势和分享规则集中到一个小 Module。
## 验收
- `npm run test -- src/components/rpg-entry/rpgEntryRecommendSwipeDeckModel.test.ts`
- `npm run test -- src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx -t "recommend|edutainment"`
- `npm run test -- src/components/rpg-entry/rpgEntryPublicGalleryViewModel.test.ts -t "recommend"`
- `npx eslint src/components/rpg-entry/rpgEntryRecommendSwipeDeckModel.ts src/components/rpg-entry/rpgEntryRecommendSwipeDeckModel.test.ts --max-warnings 0`
- `npx eslint src/components/rpg-entry/RpgEntryHomeView.tsx --quiet`
- `npm run typecheck`
- `npm run check:encoding`