Slide 32
Slide 32 text
04
ニュースフィードのDataSource
©NewsPicks Inc. All Rights Reserved.
private var diffableDataSource: UITableViewDiffableDataSource!
diffableDataSource = .init(tableView: tableView) { [weak self] tableView, indexPath, identifier -> UITableViewCell in
guard let self = self else { return UITableViewCell() }
guard let itemState = ViewStore(self.store).items[id: identifier] else { return UITableViewCell() }
let itemStore: Store = self.store.scope(
state: { $0.items[id: identifier] ?? itemState },
action: { .item(id: identifier, action: $0) }
)
switch itemState {
case .article:
let store: Store = itemStore.scope(
state: { parentState in (/FeedItemCore.State.article).extract(from: parentState)! },
action: FeedItemCore.Action.article)
let cell = tableView.dequeueReusableCell(
withIdentifier: String(describing: HostingCell.self),
for: indexPath) as! HostingCell
cell.setView(rootView: ArticleView(store: store), parentController: self)
return cell
case .video:
...