combine-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCombine Code Review
Combine代码评审
Quick Reference
快速参考
| Issue Type | Reference |
|---|---|
| Publishers, Subjects, AnyPublisher | references/publishers.md |
| map, flatMap, combineLatest, switchToLatest | references/operators.md |
| AnyCancellable, retain cycles, [weak self] | references/memory.md |
| tryMap, catch, replaceError, Never | references/error-handling.md |
| 问题类型 | 参考文档 |
|---|---|
| Publishers、Subjects、AnyPublisher | references/publishers.md |
| map、flatMap、combineLatest、switchToLatest | references/operators.md |
| AnyCancellable、循环引用、[weak self] | references/memory.md |
| tryMap、catch、replaceError、Never | references/error-handling.md |
Review Checklist
评审检查清单
- All closures use
sinkwhen self owns cancellable[weak self] - No usage (use
assign(to:on:self)or sink)assign(to: &$property) - All AnyCancellables stored in Set or property (not discarded)
- Subjects exposed as via
AnyPublishereraseToAnyPublisher() - used correctly (not when
flatMapneeded)map + switchToLatest - Error handling inside to keep main chain alive
flatMap - followed by
tryMapto restore error typesmapError - before UI updates
receive(on: DispatchQueue.main) - PassthroughSubject for events, CurrentValueSubject for state
- Future wrapped in Deferred when used with retry
- 当self持有cancellable时,所有闭包都使用
sink[weak self] - 不使用(改用
assign(to:on:self)或sink)assign(to: &$property) - 所有AnyCancellable都存储在Set或属性中(不被丢弃)
- Subjects通过暴露为
eraseToAnyPublisher()AnyPublisher - 使用正确(在需要
flatMap时不误用)map + switchToLatest - 在内部处理错误以维持主链存活
flatMap - 后跟随
tryMap以恢复错误类型mapError - UI更新前调用
receive(on: DispatchQueue.main) - PassthroughSubject用于事件,CurrentValueSubject用于状态
- 与retry一起使用时,Future包装在Deferred中
When to Load References
何时查阅参考文档
- Reviewing Subjects or publisher selection → publishers.md
- Reviewing operator chains or combining publishers → operators.md
- Reviewing subscriptions or memory issues → memory.md
- Reviewing error handling or try* operators → error-handling.md
- 评审Subjects或publisher选择 → publishers.md
- 评审操作符链或publisher组合 → operators.md
- 评审订阅或内存问题 → memory.md
- 评审错误处理或try*操作符 → error-handling.md
Review Questions
评审问题
- Are all subscriptions being retained? (Check for discarded AnyCancellables)
- Could any sink or assign create a retain cycle with self?
- Does flatMap need to be switchToLatest for search/autocomplete?
- What happens when this publisher fails? (Will it kill the main chain?)
- Are error types preserved or properly mapped after try* operators?
- 所有订阅都被保留了吗?(检查是否有被丢弃的AnyCancellables)
- 任何sink或assign是否会与self产生循环引用?
- 对于搜索/自动补全场景,flatMap是否需要替换为switchToLatest?
- 当这个publisher失败时会发生什么?(是否会导致主链中断?)
- try*操作符之后,错误类型是否被保留或正确映射?