This sample Repository has a method public LiveData<Resource<List<Repo>>> loadRepos(String owner)
https://github.com/googlesamples/android-architecture-components/blob/master/GithubBrowserSample/app/src/main/java/com/android/example/github/repository/RepoRepository.java
My question is why add Android APIs (i.e. android.arch.lifecycle.LiveData
) into a data layer?
Isn't it anti-Clean Architecture to mix framework APIs with your data/entities?
Also wouldn't it now require using Robolectric to unit test RepoRepository
?
The purpose of LiveData is to let observers know both when the data is ready and when it changes. When you return a LiveData object from a repository what you are saying is that you will get the data for the caller soon (or eventually) and that you will continue to let the caller know about changes or updates to the data. The implementation of LiveData in the Android Architecture is very simple and is independent of the core Android APIs. The Android Architecture classes are actually add-ons which make Android programming easier and more clean.
Because it is independent of the Android core you do not need Roboelectric to test it. However, you will need to manage your threads for testing because LiveData usually requires the use of a background thread to fetch the data for the observers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With