android / codelab-android-paging

Jetpack Paging codelab
Apache License 2.0
494 stars 263 forks source link

Why have you not used Live Data in this line? #158

Closed arjun1194 closed 3 years ago

arjun1194 commented 3 years ago

https://github.com/googlecodelabs/android-paging/blob/b249ec89ffd92773dcff2443da1f803c39784122/app/src/main/java/com/example/android/codelabs/paging/ui/SearchRepositoriesViewModel.kt#L34

Im trying to learn Paging 3.0 and want to know why you have not used Live Data in the view model in this project, also How would we go about using Live data along with paging 3 library. thanks!

dlam commented 3 years ago

Paging is Coroutine-first and there isn't any need to use LiveData if you are using Flow. However, you can still use LiveData via the LiveData extensions from paging-runtime.

Instead of observing Pager(..).flow, you want Pager(...).liveData. https://developer.android.com/reference/kotlin/androidx/paging/package-summary#extension-properties

dlam commented 3 years ago

The general recommendation I have though is to try to keep your app consistent to always use LiveData or always use Flow when possible.