combine-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Combine Code Review

Combine代码评审

Quick Reference

快速参考

Issue TypeReference
Publishers, Subjects, AnyPublisherreferences/publishers.md
map, flatMap, combineLatest, switchToLatestreferences/operators.md
AnyCancellable, retain cycles, [weak self]references/memory.md
tryMap, catch, replaceError, Neverreferences/error-handling.md
问题类型参考文档
Publishers、Subjects、AnyPublisherreferences/publishers.md
map、flatMap、combineLatest、switchToLatestreferences/operators.md
AnyCancellable、循环引用、[weak self]references/memory.md
tryMap、catch、replaceError、Neverreferences/error-handling.md

Review Checklist

评审检查清单

  • All
    sink
    closures use
    [weak self]
    when self owns cancellable
  • No
    assign(to:on:self)
    usage (use
    assign(to: &$property)
    or sink)
  • All AnyCancellables stored in Set or property (not discarded)
  • Subjects exposed as
    AnyPublisher
    via
    eraseToAnyPublisher()
  • flatMap
    used correctly (not when
    map + switchToLatest
    needed)
  • Error handling inside
    flatMap
    to keep main chain alive
  • tryMap
    followed by
    mapError
    to restore error types
  • receive(on: DispatchQueue.main)
    before UI updates
  • PassthroughSubject for events, CurrentValueSubject for state
  • Future wrapped in Deferred when used with retry
  • 当self持有cancellable时,所有
    sink
    闭包都使用
    [weak self]
  • 不使用
    assign(to:on:self)
    (改用
    assign(to: &$property)
    或sink)
  • 所有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

评审问题

  1. Are all subscriptions being retained? (Check for discarded AnyCancellables)
  2. Could any sink or assign create a retain cycle with self?
  3. Does flatMap need to be switchToLatest for search/autocomplete?
  4. What happens when this publisher fails? (Will it kill the main chain?)
  5. Are error types preserved or properly mapped after try* operators?
  1. 所有订阅都被保留了吗?(检查是否有被丢弃的AnyCancellables)
  2. 任何sink或assign是否会与self产生循环引用?
  3. 对于搜索/自动补全场景,flatMap是否需要替换为switchToLatest?
  4. 当这个publisher失败时会发生什么?(是否会导致主链中断?)
  5. try*操作符之后,错误类型是否被保留或正确映射?