Clament John
12/11/2021, 10:20 AMprivate val searchString = MutableStateFlow("")
val rooms = searchString.flatMapLatest {
if (it.isBlank()) {
fetchPrivateRooms()
} else {
fetchPrivateRooms().combineTransform(fetchPublicRooms()) { priv, pub ->
emit(filterRooms(priv, pub, it))
}
}
}.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
Q: How do I do this if fetchPrivateRooms
returns a LiveData<List<Rooms>>
instead of a flow? I can't use observeAsState directly as I wish to merge and transform the data coming from the data source
What is my usecase?
I wish to use a library that uses livedata extensively in Compose. I've previously use the above code when I was working with flow
But don't know how to merge and transform livedata within a viewmodel. Note: This business logic is to be seperated from the UI logic and so I can't use a lifecycleowner (I think)Nick Allen
12/12/2021, 12:47 AMfetchPublicRooms().asFlow()
Nick Allen
12/12/2021, 12:48 AM