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

Reusing Features in a RecyclerView #142

Open
JonWatson opened this issue Dec 9, 2020 · 1 comment
Open

Reusing Features in a RecyclerView #142

JonWatson opened this issue Dec 9, 2020 · 1 comment
Labels
question Further information is requested

Comments

@JonWatson
Copy link

We have a variety of complicated cards to use in a RecyclerView and we would like to use a Feature for each card. The cards observe multiple Observable sources, and need to be disposed of properly when recycled/backgrounded/etc.

  1. Should we be calling .dispose() on a Feature that belongs to a card that is being recycled?

  2. Is there a way to re-use a Feature after it has been .disposed()? We would rather not have to allocate new Features in onBindViewHolder() as the object allocations can lead to GC/jank.

  3. How does the Binder that we use play into this? Do we need to call .dispose() on it as well? Or is that unnecessary if we are calling .dispose() on each bound Feature when it's no longer needed?

Thank you!

@zsoltk
Copy link
Contributor

zsoltk commented Dec 14, 2020

Hey @JonWatson !

3.: This seems to be the easiest to answer. You can think of Binder as a shortcut for making a .subscribe() call on an Observable. So those subscriptions need to be disposed of. Features are hot observables though, and will continue undisturbed (see: documentation)

1.: Following from the above, yes

2.: If you already called .dispose() then you can't re-use the same instance anymore. In your use case however, instead of directly calling .dispose(), you can have e.g. a .takeUntil() operator in your Feature's Actor to use some signal stream, and push an element into that when you need it to stop. In this case though, it's another question which scope will you store your Feature instance in and when will you actually dispose of it.

@zsoltk zsoltk added the question Further information is requested label Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants