I love the concepts behind this library and I actually built my own for dealing with UICollectionView
in a reactive manner.
There's a couple of challenges/problems I've come across, some that this library faces too.
This one isn't really a problem, I solved it by making my initializer look like:
init(collectionView: UICollectionView, dataSignal: SignalProducer<[[T]], NoError>, supplementarySignal: SignalProducer<[String: [T]], NoError>?) { }
where the data signal is an array of arrays to represent multiple sections. I'm not sure that there is a better way to do it.
Every time the data signal changes, the table view reloads all it's data. But what about, instead of using AnyObject
, use generic parameters that conform to Equatable
so you can produce diffs of the previous and current data arrays?
This becomes really tricky when dealing with multiple sections because it's hard to produce a diff on multi-dimensional arrays, especially in a reactive way. Right now, I'm using Dwift to produce the diffs but the closest I can come right now is calculating the diffs as a side-effect:
self.data.producer.observeOn(UIScheduler()).throttle(0.1, onScheduler: QueueScheduler.mainQueueScheduler).on(next: { [unowned self] in
guard let collectionView = self.collectionView else { return }
for (index, element) in $0.enumerate() {
if index == self.diffCalculators.count {
let calculator = CollectionViewDiffCalculator<T>(collectionView: collectionView, initialRows: element)
calculator.sectionIndex = index
self.diffCalculators.append(calculator)
} else {
let calculator = self.diffCalculators[index]
calculator.rows = element
}
}
})
.takeUntil(self.willDeallocSignal())
.start()
@ColinEberhardt would you have any suggestions on how to improve upon that?