Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to remove ~ #1

Open
lm2343635 opened this issue Apr 16, 2019 · 6 comments
Open

Possible to remove ~ #1

lm2343635 opened this issue Apr 16, 2019 · 6 comments

Comments

@lm2343635
Copy link
Member

lm2343635 commented Apr 16, 2019

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
Copy link
Member Author

lm2343635 commented Aug 9, 2019

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

@ianhwu
Copy link

ianhwu commented Aug 9, 2019

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.

@lm2343635
Copy link
Member Author

lm2343635 commented Aug 9, 2019

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

@o-nnerb
Copy link

o-nnerb commented May 2, 2020

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

@lm2343635
Copy link
Member Author

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

@knottx
Copy link

knottx commented Mar 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants