Has I read more about Flow I'm starting to think that you can replace MutableLiveData switchMap pattern with something similar with flow.
You can replace LiveData observation with flow by implementing something like this but I'm unable to imagine how to replace the switchMap part.
By switchMap pattern I mean this:
val mutableLiveData: MutableLiveData<SomeClass> = MutableLiveData()
val liveData: LiveData<SomeOtherClass> = mutableLiveData
.switchMap {
//call to repo
}
Is there anything equivalent or am I missing out something completely? Or even thinking about flow completely the wrong way.
The equivalent is Flow.flatMapLatest((T) -> Flow<R>)
. They actually removed the. Flow.switchMap
function in favour of a few new mapLatest
functions.
However this has been marked as experimental for now so use it with caution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.