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

From AnyObserver to RxCocoa.Binding #4

Merged
merged 3 commits into from
Jul 28, 2018
Merged

From AnyObserver to RxCocoa.Binding #4

merged 3 commits into from
Jul 28, 2018

Conversation

kasyanov-ms
Copy link
Member

@kasyanov-ms kasyanov-ms commented Jun 5, 2018

PR makes a binding implementation similar to UIImageView extension
The basic usage is:

viewModel
    .imageUrl
    .drive(imageView.kf.rx.image(placeholder: placeholder))
    .disposedBy(disposeBag)

But there is still one design issue. Since we cannot bind Observable<URL> to Binding<Resource>, the current workaround is Binding<URL?> return type. The other choices:

  • Return Binding<Resource?>. The same element type as in the current version. The drawback is repeating map { $0 as Resource? } typecasting
  • Separate Resource and URL bindings. Code duplicating

@rxswiftcommunity
Copy link

rxswiftcommunity bot commented Jun 5, 2018

Warnings
⚠️

It looks like code was changed without adding anything to the Changelog. If this is a trivial PR that doesn't need a changelog, add #trivial to the PR title or body.

Thanks a lot for contributing @kasyanov-ms! I've invited you to join the
RxSwiftCommunity GitHub organization – no pressure to accept! If you'd like
more information on what this means, check out our contributor guidelines
and feel free to reach out with any questions.

Generated by 🚫 dangerJS

@kasyanov-ms
Copy link
Member Author

If PR is Ok, I'll update the changelog and examples

@freak4pc
Copy link
Member

freak4pc commented Jul 15, 2018

Thanks @kasyanov-ms. What's the up-side of switching from AnyObserver to Binder in this case? Especially given the fact Binder is just a wrapper for AnyObserver?

@kasyanov-ms
Copy link
Member Author

kasyanov-ms commented Jul 27, 2018

Hello. AnyObserver keeps a strong reference to our UIImageView. I've made a simple project. The top image is binding to AnyObserver, we cannot deallocate it. The bottom one is from the fork, it works as it should be.

@freak4pc
Copy link
Member

This is really interesting. I would imagine the [base] capture group would make sure to properly keep a safe reference, but I think the issue is base refers to Kingfisher and not its associated ImageView.

Anyways, looks good to me! Thank you.

@freak4pc freak4pc merged commit 1451911 into RxSwiftCommunity:master Jul 28, 2018
@freak4pc
Copy link
Member

Thanks for your contribution, and welcome to RxSwiftCommunity!

@kasyanov-ms kasyanov-ms deleted the rxcocoa-binder branch July 28, 2018 16:45
@kasyanov-ms
Copy link
Member Author

kasyanov-ms commented Jul 28, 2018

I think the issue is base refers to Kingfisher and not its associated ImageView

Yeap, it was possible to achieve the same with weak base.base, but the solution becomes a little bit dirty

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

Successfully merging this pull request may close these issues.

2 participants