RxSwiftCommunity/RxBinding

Possible to remove ~

lm2343635 opened this issue · 6 comments

I am considering how to remove the operator ~ after the Binder or the ControlEvent property.

viewModel.text ~> label.rx.text

If anyone has a good idea about this, please contact me here or create a PR.
Thanks.

I don't understand what you mean.
The operator ~> is equal to bind(to:).
viewModel.text ~> label.rx.text == viewModel.text.bind(to: label.rx.text)
@yansaid
I mean how to combine the method disposed(by:) into the operator ~>.

I don't understand what you mean.
The operator ~> is equal to bind(to:).
viewModel.text ~> label.rx.text == viewModel.text.bind(to: label.rx.text)
@yansaid
I mean how to combine the method disposed(by:) into the operator ~>.

Oh, sorry, I understand it wrong. Deleted it.

Do you have other ideas to solve this problem. @yansaid

I did this in some classes to remove the disposeBag dependency. This solution is only available to classes objects.

So, what I did was to set disposeBag to nil when the class object is deallocating.

extension UIView {
    func setSomeObservable(_ observable: Observable<Void>) {
         var disposeBag: DisposeBag! = .init()
  
         observable.subscribe(onNext: { _ in
             print("Subscribed") 
         }).disposed(by: disposeBag)

         self.rx.deallocating.subscribe(onNext: { _ in
             disposeBag = nil
         }).disposed(by: disposeBag)
    }
}

I've tried such solutions, sometimes it not works and caused memory leaks

you can use
viewModel.text ~> label.rx.text ~ disposeBag
shorter than
viewModel.text.bind(to: label.rx.text).disposed(by: disposeBag)