Having in mind a form with 10 fields (for instance...
# compose
n
Having in mind a form with 10 fields (for instance) of different types (text, radio button, checkbox, combobox, … ). What do you folks think is the best approach? 1️⃣ Expose one `Flow`/`LiveData` for each field in ViewModel and collect/observe them individually in the screen. 2️⃣ Expose one
State
for each field in ViewModel and simply access them from the screen. 3️⃣ Encapsulate these 10 fields in a data class, expose one single `Flow`/`LiveData` and each “setter” create a
copy
of this data class instance to update the state. 4️⃣ Encapsulate these 10 fields in a data class, each field is a state, ViewModel has an instance of this class and you simply access it from the screen. 5️⃣ Other (please explain)
2️⃣ 1
5️⃣ 2
3️⃣ 6
I’m currently using 3️⃣ because I don’t want my viewmodel depends on Compose classes (State).
c
A single state class with multiple mutable state ofs
💯 3
t
Been migrating from Flow to snapshot state (^), this is the way to go for sure
o
Flow/StateFlow are not great as observable properties, their asynchrony can lead to unexpected behavior. See https://github.com/Kotlin/kotlinx.coroutines/issues/2280 for more information.
g
Flow/StateFlow are not great as observable properties
It’s completely fine behaviour for observable property, otherwise you will get all those “unexpected behavior” not when you do this syncronously, but when you do this asyncronously