2020-12-10 03:44:06 +01:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import ViewModels
|
|
|
|
|
|
|
|
final class NewStatusDataSource: UICollectionViewDiffableDataSource<Int, Composition.Id> {
|
2020-12-16 02:39:38 +01:00
|
|
|
private let updateQueue =
|
|
|
|
DispatchQueue(label: "com.metabolist.metatext.new-status-data-source.update-queue")
|
|
|
|
|
2020-12-10 03:44:06 +01: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 02:39:38 +01:00
|
|
|
|
|
|
|
override func apply(_ snapshot: NSDiffableDataSourceSnapshot<Int, Composition.Id>,
|
|
|
|
animatingDifferences: Bool = true,
|
|
|
|
completion: (() -> Void)? = nil) {
|
|
|
|
updateQueue.async {
|
|
|
|
super.apply(snapshot, animatingDifferences: animatingDifferences, completion: completion)
|
|
|
|
}
|
|
|
|
}
|
2020-12-10 03:44:06 +01:00
|
|
|
}
|