I have some questions regarding the functions that are defined as extensions on
MutableStateFlow
.
On Android at least, I’ve opted to basically completely stop using this pattern
private val _state = MutableStateFlow(…)
val state = _state.asStateFlow()
to handle screen state, as this more often than not means that you are then creating some hot state that lives for the entire time that the state holder lives for, and does not care for if there are any consumers at the time or not. So this means that if you are listening to any cold flow, you’re turning it hot and are listening to it, even if there may be nobody listening on the values that it produces.
Instead, it’s always better to define a bunch of cold flows for data transformations etc. and then combine them all together in a chain like:
combine(flow1, flow2) { _, _ -> ...}
.stateIn(...)
To get the final
StateFlow
which is going to be public API of the state holder class.
So this means that I never end up having a
MutableStateFlow
instance to use those extension functions for. Is this something that you folks still end up using? Is this too much of an Android concern perhaps?