DenTelezhkin / DTTableViewManager

Protocol-oriented UITableView management, powered by generics and associated types.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RxSwift extension

orkenstein opened this issue · comments

Trying to implement reactive extension for DTTableViewManager, like this:

extension DTTableViewManager {
  func rx_modelSelected<T:ModelTransfer where T:UICollectionViewCell>(cellClass: T.Type) -> Observable<(T, T.ModelType, NSIndexPath)>{
    Observable<(T, T.ModelType, NSIndexPath)>.create { [weak self]  (observer) -> Disposable in
      self?.whenSelected(cellClass) { cell, model, indexPath -> Void in
        observer.onNext((cell, model, indexPath))
      }
    }
  } 
}

But whenSelected gives an error:
Value of type 'DTTableViewManager' has no member 'ModelType'

I'm not very familiar with typealias. How to make this work?

I have not much experience with RxSwift, however following should work:

extension DTTableViewManager {
    func rx_modelSelected<T:ModelTransfer where T:UITableViewCell>(cellClass: T.Type) -> Observable<(T, T.ModelType, NSIndexPath)>{
        return Observable<(T, T.ModelType, NSIndexPath)>.create { [weak self] observer -> Disposable in
            self?.whenSelected(T.self, {
                observer.onNext($0)
            })
            return NopDisposable.instance
        }
    } 
}

@orkenstein Possibly, onCompleted call is not necessary, sorry, i edited my previous response

@DenHeadless, thanks. The problem was my inattention:
T:UICollectionViewCell instead of T:UITableViewCell
Yep, completed will close the channel immediately.