Is there any rule of thumb when to bundle multiple single states of a
into one state object (e.g.
data class ViewState(..)
)? In my opinion both have advantages and disadvantages. Exposing multiple states from VM keeps changes to the UI more granular but it's more cumbersome to keep track of every single state. On the other hand, exposing just one bigger state object has better maintenance because you always have to deal with just one state in your UI but in contrast when one of the fields changes, a new object is created. Imagine you have following state object:
You can map states as sealed classesSorted items should derive of your loaded itemsThese states should be mutually exclusive, you wouldn't want any corner unturned
1 year ago
Thanks but this question is not about sorted items or map states as sealed classes. It's about when to use which approach, the state class above is just an example. It could be of 2 fields but also of 10 fields
To be honest I have the exact same struggle. Sometimes I feel like it would be easier to create UIState objects for every screen. But It just does not feel right to update the whole screen for every little change that occurs. At the moment we are exposing multiple StateFlows from the VM and collect them and pass them down the view hierarchy as needed. But it would be nice to have official guidelines regarding this topic.