Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created November 17, 2017 14:08
Show Gist options
  • Save Dimillian/6b9ab52dfbd0e13f7739f2130d2c6ad3 to your computer and use it in GitHub Desktop.
Save Dimillian/6b9ab52dfbd0e13f7739f2130d2c6ad3 to your computer and use it in GitHub Desktop.
BooksCollectionViewController
class BooksCollectionViewController: UIViewController {
@IBOutlet var collectionView: UICollectionView!
var booksCollectionInterfaceProvider: BooksCollectionInterfaceProvider!
var booksCollectionDataProvider: BaseBooksCollectionDataProvider! {
didSet {
title = booksCollectionDataProvider.title
if booksCollectionDataProvider.datasource.isEmpty {
booksCollectionDataProvider.loadData(paginationDelegate: self.paginationDelegate)
}
}
}
var _paginationDelegate = PaginationDelegate()
override func viewDidLoad() {
super.viewDidLoad()
booksCollectionInterfaceProvider = BooksCollectionInterfaceProvider(parentController: self,
collectionView: collectionView)
booksCollectionInterfaceProvider.delegate = self
if !booksCollectionDataProvider.datasource.isEmpty {
booksCollectionInterfaceProvider.datasource = booksCollectionDataProvider.datasource
self.paginationDelegate.offset = 0
self.paginationDelegate.limit = booksCollectionDataProvider.datasource.count
}
store.subscribe(self) {
$0.select{ $0.usersState }
}
}
}
extension BooksCollectionViewController: BooksCollectionInterfaceProviderDelegate {
func booksCollectionInterfaceProviderCollectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize.zero
}
func booksCollectionInterfaceProviderCollectionView(collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String,
at indexPath: IndexPath) -> UICollectionReusableView {
return UICollectionReusableView()
}
func booksCollectionInterfaceProviderScrollViewDidScroll(scrollView: UIScrollView) {
}
func booksCollectionInterfaceProviderDidChangeDisplayMode(provider: BooksCollectionInterfaceProvider,
displayMode:)
}
}
extension BooksCollectionViewController: StoreSubscriber {
func newState(state: UsersState) {
DispatchQueue.main.async {
self.booksCollectionInterfaceProvider.datasource = self.booksCollectionDataProvider.datasource
}
}
}
extension BooksCollectionViewController: PaginatedScrollView {
var paginationDelegate: PaginationDelegate {
return _paginationDelegate
}
func paginationShouldLoad(offset: Int, limit: Int) {
booksCollectionDataProvider.loadData(paginationDelegate: self.paginationDelegate)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment