frankelot
06/17/2021, 11:22 PMfrankelot
06/17/2021, 11:25 PMfrankelot
06/17/2021, 11:27 PMfrankelot
06/17/2021, 11:35 PMfrankelot
06/18/2021, 12:02 AMIan Lake
06/18/2021, 12:04 AMfrankelot
06/18/2021, 12:10 AM@Composable
fun MainScreen() {
val vm = viewModel()
....
Foo()
...
}
@Composable
fun Foo() {
val anotherVm = viewModel()
....
}
frankelot
06/18/2021, 12:21 AMtad
06/18/2021, 2:04 AMfrankelot
06/18/2021, 8:19 AMfrankelot
06/18/2021, 8:19 AMit doesn’t need to be monolithicWould love to learn more about this though, how can I avoid a god VM in very complex screens 🤔 … should I just use 2 or more VMs at the top level
Cicero
06/20/2021, 10:41 AMCicero
06/20/2021, 10:50 AMfrankelot
07/06/2021, 7:28 AMfrankelot
07/06/2021, 7:30 AMdarkmoon_uk
09/27/2021, 11:43 PMTextField
and Drop-Down List components constructed from TextField
and DropDownMenu
. Each component has its own sub-VM to manage loading of data/valid states; validation of input both in real-time and at final submission etc. These are clearly reusable units of business logic that mirror the View layer in structure. Hard to imagine having it any other way... copying and pasting this functionality in a single VM would be 🤢. Structuring presentation logic alongside the View feels natural to me and also encourages keeping the View layer (Compose declarations) as thin as possible, meaning easier portability to other systems/flavours of View layer (e.g. Compose for Web). At the end of the day it's whatever works for you - here's a counter-point 🙂