igorwojda / android-showcase

💎 Android application following best practices: Kotlin, Coroutines, JetPack, Clean Architecture, Feature Modules, Tests, MVVM, DI, Static Analysis...
MIT License
6.48k stars 895 forks source link

Multiple LiveData same viewmodel #72

Closed l3vick closed 2 years ago

l3vick commented 4 years ago

Hi Igor, I am a follower of your best practices and I am trying to implement them in my own projects.

My problem is that I have to make 6-8 request in the same view. At the begining I was using the same stateLiveData to display all the lists but it was not working really well and now I have created multiple Observables in my viewmodel but I cannot use the same BaseViewModel as I have to add differents ViewActions and ViewStates as type arguments, also 400 new lines of code spread between classes.

So my question is: Do you have an example on how to do this? Is there a clean solution? My app is working well this way but I feel myself that I am desecrating your code.

Edit: I am using the same instance of stateTimeTravellerDebugger in BaseViewAction. When I have many ViewStates and ViewActions, I have noticed that sometimes when the request are arriving at the same time, stateTimetravellerDebbuger lastViewAction is null. Maybe what I am trying to do is not the best, should I create one logger for any ViewState I have?.

Many Thanks.

igorwojda commented 2 years ago

This app is designed to have a single state (single LiveData stream) as a view state. Few streams will not work well with this approach.