is it more idiomatic/preferred to expose a `mutabl...
# compose
d
is it more idiomatic/preferred to expose a
mutableStateOf
or a
StateFlow
/
LiveData
property from a ViewModel?
l
I would prefer Flow, since it’s available on all platforms and doesn’t rely on any libraries that aren’t in the standard library.
K 3
c
I think mutableStateOf is idiomatic. Definitely not livedata if you can avoid it
2
d
I noticed this https://developer.android.com/jetpack/compose/state#viewmodels-source-of-truth, but it feels like we are putting view implementation/related API's inside the ViewModel if we use
mutableStateOf
l
If you use Flow, you can create your state in compose using
val state by fooFlow.collectAsState(defaultFoo)
to avoid having to put
state.value
everywhere. You can just use the state variable directly, which I find idiomatic enough. Bonus points for using a data class for state and having your state for the screen all come from a single flow.
👍 1
d
Most of the implementation here exposes flows from the viewmodel and not a
mutableStateOf
property https://github.com/android/nowinandroid