Produces state by using a StateProducer that merges flows that carry functions that lazily modify the state.
This avoids the issues that can arise when combining flows:
The limited arity of the combine function
The difficulty of merging the effects of user actions into the state production pipeline
There are a probably a few rough edges, but it has an element of consistency across all ViewModels.
This change has the interesting side effect of only being able to push state changes only if there is an observer of UI state. If there is no observer of state, all pending pushes will suspend until an observer is present.
It also means and coroutines launched have to honor the SharingStarted passed to the StateProducer. This means both Flows and suspend functions in ViewModels only run as specified by WhileUiSubscribed which is SharingStarted.WhileSubscribed(5_000).
Produces state by using a
StateProducer
that merges flows that carry functions that lazily modify the state.This avoids the issues that can arise when combining flows:
This change has the interesting side effect of only being able to push state changes only if there is an observer of UI state. If there is no observer of state, all pending pushes will suspend until an observer is present.
It also means and coroutines launched have to honor the
SharingStarted
passed to theStateProducer
. This means bothFlows
andsuspend
functions in ViewModels only run as specified byWhileUiSubscribed
which isSharingStarted.WhileSubscribed(5_000)
.It also lets users just
setState
.