RxBinding icon indicating copy to clipboard operation
RxBinding copied to clipboard

Possible to remove ~

Open lm2343635 opened this issue 5 years ago • 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.

lm2343635 avatar Apr 16 '19 06:04 lm2343635

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 ~>.

lm2343635 avatar Aug 09 '19 03:08 lm2343635

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.

ianhwu avatar Aug 09 '19 03:08 ianhwu

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

lm2343635 avatar Aug 09 '19 04:08 lm2343635

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)
    }
}

o-nnerb avatar May 02 '20 13:05 o-nnerb

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

lm2343635 avatar May 12 '20 07:05 lm2343635

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

knottx avatar Mar 10 '22 07:03 knottx