SectionReactor

Swift CocoaPods Build Status Codecov

SectionReactor 是 ReactorKit 的一个扩展,用于使用 RxDataSources 管理表格视图和集合视图的分区。

快速开始

这是一个草稿。 我不知道该如何解释这个概念 🤦‍♂️ 最好查看 ArticleFeed 示例。

ArticleViewSection.swift

enum ArticleViewSection: SectionModelType {
  case article(ArticleSectionReactor)

  var items: [ArticleViewSection] {
    switch self {
    case let .article(sectionReactor):
      return sectionReactor.currentState.sectionItems
    }
  }
}

ArticleSectionReactor.swift

import SectionReactor

final class ArticleSectionItem: SectionReactor {
  struct State: SectionReactorState {
    var sectionItems: [ArticleSectionItem]
  }
}

ArticleListViewReactor.swift

final class ArticleListViewReactor: Reactor {
  struct State {
    var articleSectionReactors: [ArticleSectionReactor]
    var sections: [ArticleViewSection] {
      return self.articleSectionReactors.map(ArticleViewSection.article)
    }
  }

  func transform(state: Observable<State>) -> Observable<State> {
    return state.merge(sections: [
      { $0.articleSectionReactors },
    ])
  }
}

依赖

安装

pod 'SectionReactor'

许可

SectionReactor 基于 MIT 许可。 有关更多信息,请参见 LICENSE