You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
switch between a triggering flow of UI events growZoneFlow and an output flow to introduce a flow API of flatMapLatest
growZoneFlow.flatMapLatest{ another flow }
This pattern shows how to integrate events (grow zone changing) into a flow. It does exactly the same thing as the LiveData.switchMap version–switching between two data sources based on an event.
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)
}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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,
plantsFlow
andgetPlantsWithGrowZoneFlow
for the particular example appgrowZoneFlow
and an output flow to introduce a flow API offlatMapLatest
Personally, it makes more sense to refer to the API of
flatMapLatest
,in that case, these information consuses me:The text was updated successfully, but these errors were encountered: