Home > Mobile >  How to make a proper reactive extension on Eureka SelectableSection
How to make a proper reactive extension on Eureka SelectableSection

Time:12-02

This is my first question to the StackOverflow community so excuse me if I'm doing something wrong.

1. What I'm trying to achieve
Basically, I want to make a custom reactive wrapper around Eureka's SelectableSection class in order to observe the value of the selected row when it is changed. I'm thinking to get this data from the onSelectSelectableRow closure which is called every time a row is selected.

2. What I've tried to do for that
Actually, I've got this working but it's not a generic use of the custom wrapper, here is the example that works but only when I specify the row and its value type, for example ListCheckRow<Int>.

extension SelectableSection: ReactiveCompatible {}
extension Reactive where Base : SelectableSection<ListCheckRow<Int>> {
  var selectedValue: Observable<Base.SelectableRow.Cell.Value?> {
    return Observable.create { observer in
      self.base.onSelectSelectableRow = {cell, row in
        observer.onNext(row.value)
      }
      return Disposables.create {
        observer.onCompleted()
      }
    }
  }
}

This works fine and as I expected but when it comes to something more generic like the next code example, I get an error saying that: "Cannot assign to property: 'base' is a 'let' constant"

extension SelectableSection: ReactiveCompatible {}
extension Reactive where Base : SelectableSectionType {
  var selectedValue: Observable<Base.SelectableRow.Cell.Value?> {
    return Observable.create { observer in
      self.base.onSelectSelectableRow = {cell, row in // Error: Cannot assign to property: 'base' is a 'let' constant
        observer.onNext(row.value)
      }
      return Disposables.create {
        observer.onCompleted()
      }
    }
  }
}

Any help will be much appreciated, thanks.

  • Related