kevin.cianfarini
10/27/2020, 3:07 AMonEach
with MutableStateFlow
and return a MutableStateFlow
?
My use case -- calling SavedStateHandle.getLiveData(key: String)
will automatically save new emissions to that live data into the saved state. I would like something like this to be possible with StateFlow
fun <T> SavedStateHandle.getStateFlow(key: String, defaultValue: T): MutableStateFlow<T> {
return MutableStateFlow(this[key] ?: defaultValue).onEach {
this[key] = it
}
}
However, onEach
returns a regular instance of Flow
. Is this something that's been discussed? If not, I'm more than willing to open an issue.Zach Klippenstein (he/him) [MOD]
10/27/2020, 4:17 PMonEach
.
If you file this, you might want to contrast it with the issue I filed: https://github.com/Kotlin/kotlinx.coroutines/issues/2081kevin.cianfarini
10/27/2020, 4:28 PMZach Klippenstein (he/him) [MOD]
10/27/2020, 5:57 PMkevin.cianfarini
10/28/2020, 2:15 PMkevin.cianfarini
10/28/2020, 5:41 PM