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

LiveData and ViewModel implementation #4

Open
ash995 opened this issue Feb 13, 2018 · 3 comments
Open

LiveData and ViewModel implementation #4

ash995 opened this issue Feb 13, 2018 · 3 comments
Labels

Comments

@ash995
Copy link

ash995 commented Feb 13, 2018

You can have the presenter be a subclass of the ViewModel class and update data on the ui with the help of LiveData.
If you think it's a good idea I'd like to work on it.

@quangctkm9207
Copy link
Owner

Hi @ash995 , thank you for being interested in this project.
If LiveData is utilized, RxJava should be removed.
About ViewModel, it is a good idea and I'm considering about it.

@4gus71n
Copy link

4gus71n commented Oct 11, 2018

Great example @quangctkm9207 just one little bit of advice; You don't need to replace RxJava with LiveData or vice-versa.

LiveData should be use to communicate the ViewModel to the UI layer back and forth, while RxJava should be use as glue to hold together your UseCases/Interactors components. If you are using UseCases/Interactors to execute the business rules (let's say fetch a list of users from an API endpoint and then save it into a database cache) then these UseCases/Interactors are going to be injected with different repositories (Network Repositories using Retrofit if you are going to call the API, DB Repositories using Room, Ormlite or any other DB tech if you are going to fetch from the DB) and these repositories can be connected one with another using the RxJava methods (For example, flatMap if you want to wait for the API request to end and then save in the DB, merge if you want to return both responses merged)

TL;DR You can use LiveData between the UI layer and the ViewModel/Presenter layer and RxJava beneath the UseCase/Interactor layer.

@quangctkm9207
Copy link
Owner

@4gus71n : Thanks for your suggestion.
I agree with what you pointed out, but it just seems that you are mixing up several architectures here.
This project leverages MVP architecture.
LiveData is made to work well with MVVM which Google leverages, and UseCase/Interactor are parts of Clean Architecture that I created a separate example here.

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

No branches or pull requests

3 participants