metatext/Data Sources/NewStatusDataSource.swift

31 lines
1.2 KiB
Swift
Raw Normal View History

2020-12-10 02:44:06 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import UIKit
import ViewModels
2020-12-18 00:17:17 +00:00
final class NewStatusDataSource: UICollectionViewDiffableDataSource<Int, CompositionViewModel.Id> {
2020-12-16 01:39:38 +00:00
private let updateQueue =
DispatchQueue(label: "com.metabolist.metatext.new-status-data-source.update-queue")
2020-12-10 02:44:06 +00:00
init(collectionView: UICollectionView, viewModelProvider: @escaping (IndexPath) -> CompositionViewModel) {
let registration = UICollectionView.CellRegistration<CompositionListCell, CompositionViewModel> {
$0.viewModel = $2
}
super.init(collectionView: collectionView) { collectionView, indexPath, _ in
collectionView.dequeueConfiguredReusableCell(
using: registration,
for: indexPath,
item: viewModelProvider(indexPath))
}
}
2020-12-16 01:39:38 +00:00
2020-12-18 00:17:17 +00:00
override func apply(_ snapshot: NSDiffableDataSourceSnapshot<Int, CompositionViewModel.Id>,
2020-12-16 01:39:38 +00:00
animatingDifferences: Bool = true,
completion: (() -> Void)? = nil) {
updateQueue.async {
super.apply(snapshot, animatingDifferences: animatingDifferences, completion: completion)
}
}
2020-12-10 02:44:06 +00:00
}