I have to spend a lot of time learning and implementing Livedata (especially MediatorLivedata) in business logic because it helps to add data from various sources. Had a success with it, because I could add FCM, Network or RoomDatabase as different sources to my MediatorLivedata and observe it in ViewModel. Its actually scales very well. However, it still lacks powerful RxJava2 implementation, like chaining requests well, flat map and etc. It seems that RxJava is used primarily in Business logic, but in fact, I saw a lot of companies using RxJava with UI with additional features/libraries. This actually makes LiveData irrelevant in presentation logic. So I would like to know if LiveData is somehow better/cleaner in presentation logic(using it in a ViewModel) vs RxJava. What would you suggest looking into the future?
RxJava is neither better nor worse to LiveData, it is different. Android Architecture Components was designed to give a model architectural pattern to android developers. So, if you're comfortable with LiveData, use that, or if you're comfortable with RxJava, use that. You can do all operations using both libraries. Though RxJava do contain a lot of syntactic sugar, same can be achieved using Livedata also.
ViewModel
as I guess it will have both LD and RxJava code. –
Mimir I think you can use RxJava and LiveData altogether. RxJava will use to under Model layer, use it for the request and receive data from the server or from the local database.
Then the LiveData will be registered to the Activity/Fragment because with LiveData you can handle the Activity/Fragment life-circle easily, and it was designed for that purpose.
ViewModel
as it will combine both LD and RxJava (right?). –
Mimir © 2022 - 2024 — McMap. All rights reserved.