RxSkeleton
RxSkeleton copied to clipboard
modelSelected
Hi @AnyOptional! Thanx for such a great lib
Presently, modelSelected feature of rxDataSources doesn't work.
I suggest writing another reactive extension
var skeletonDataSource: DelegateProxy<UICollectionView, SkeletonCollectionViewDataSource> { return RxCollectionViewSkeletonedDataSourceProxy.proxy(for: base) }
func skeletonModel<T>(at indexPath: IndexPath) throws -> T { guard let dataSource = skeletonDataSource.forwardToDelegate() as? SectionedViewDataSourceType else { fatalError("This method only works in case one of the rx.itemsWith* methods was used.") } guard let element = try dataSource.model(at: indexPath) as? T else { fatalError("Error casting") } return element }
func skeletonModelSelected<T>(_ modelType: T.Type) -> ControlEvent<T> {
let source: Observable<T> = itemSelected
.flatMap { [weak view = self.base as UICollectionView] indexPath -> Observable<T> in
guard let view = view else {
return Observable.empty()
}
return Observable.just(try view.rx.skeletonModel(at: indexPath))
}
return ControlEvent(events: source)
}
Would be grateful if you implement such feature
@rimskiynikita This is a great improvement! I've tested my code and it really doesn't work. This code was written when I was doing research, but it was not used in production, so I ignored this feature. You may know that this code is now part of SkeletonView, I'd like you make PR there although I'll add this feature here. Thanks for your great job!