android / codelab-kotlin-coroutines

Kotlin Coroutines codelab
Apache License 2.0
552 stars 268 forks source link

Something that is misleading in codelab: Learn advanced coroutines with Kotlin Flow and LiveData #179

Open tangkegaga opened 1 year ago

tangkegaga commented 1 year ago

In chapter 12, https://developer.android.com/codelabs/advanced-kotlin-coroutines#11 The title is Switching between two flows There are two cases of switching,

Inside the flatMapLatest, we switch based on the growZone. This code is pretty much the same as the LiveData.switchMap version, with the only difference being that it returns Flows instead of LiveDatas

Personally, it makes more sense to refer to the API of flatMapLatest,in that case, these information consuses me:

Basically, this lets us switch between different flows based on the value of growZone. Flow's flatMapLatest extensions allow you to switch between multiple flows. PlantListViewModel.kt if (growZone == NoGrowZone) { plantRepository.plantsFlow } else { plantRepository.getPlantsWithGrowZoneFlow(growZone) }