Skip to content
This repository was archived by the owner on May 21, 2020. It is now read-only.
This repository was archived by the owner on May 21, 2020. It is now read-only.

modelSelected #2

@rimskiynikita

Description

@rimskiynikita

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions