metatext-app-ios-iphone-ipad/Data Sources/NewStatusDataSource.swift

31 lines
1.2 KiB
Swift
Raw Normal View History

2020-12-10 03:44:06 +01:00
// Copyright © 2020 Metabolist. All rights reserved.
import UIKit
import ViewModels
2020-12-18 01:17:17 +01:00
final class NewStatusDataSource: UICollectionViewDiffableDataSource<Int, CompositionViewModel.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
2020-12-18 01:17:17 +01:00
override func apply(_ snapshot: NSDiffableDataSourceSnapshot<Int, CompositionViewModel.Id>,
2020-12-16 02:39:38 +01:00
animatingDifferences: Bool = true,
completion: (() -> Void)? = nil) {
updateQueue.async {
super.apply(snapshot, animatingDifferences: animatingDifferences, completion: completion)
}
}
2020-12-10 03:44:06 +01:00
}