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

Returning LiveData from UseCases #90

Open
svc985 opened this issue Mar 22, 2020 · 3 comments
Open

Returning LiveData from UseCases #90

svc985 opened this issue Mar 22, 2020 · 3 comments

Comments

@svc985
Copy link

svc985 commented Mar 22, 2020

Hello,
This project was such an immense Clean Architecture learning tool for me. I'd like to ask what would be a way of returning LiveData from a use case, for example, returning LiveData<List<Movie>>
from GetMovies use case and displaying it in MoviesFragment?

Thanks.

@Zhuinden
Copy link

I tend to return io.reactivex.Single from "use-case-like things", but I also instead observe the local data store for io.reactivex.Observable directly.

Not sure why you'd want to return LiveData from a usecase.

@Varsha-29
Copy link

LiveData is associated with the lifecycle of the activity/fragment and generally used between viewmodel - activity/fragment communication. To observe something in usecase, we could make use of coroutine's channels and flows.
In the viewmodel, we could use Live data builder to wrap the flow into live-data
https://proandroiddev.com/kotlin-flow-on-android-quick-guide-76667e872166

@Zhuinden
Copy link

UseCases shouldn't even be stateful. 🤔 That's why LiveData.onActive is powerful, although it'd allow you to lose results if you try to emit multiple events rather than just success/error.

But you don't need LiveData for a success/error.

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

3 participants