Kyant
07/29/2022, 11:19 AMMutableState in the init function of ViewModel?MR3Y
07/29/2022, 11:27 AMsnapshotFlow{ } ?Kyant
07/29/2022, 12:08 PMMR3Y
07/29/2022, 12:44 PMMutableState directly in VM?Kyant
07/29/2022, 12:48 PMMR3Y
07/29/2022, 1:02 PM@Composable function because being in a composable context gives you additional benefits automatically like invalidating composition, layout or drawing when state changes because Compose is monitoring snapshot reads for you under the hood. this is not the case in the VM, it doesn't know how to monitor & observe those snapshot reads for you. So, you are using some utilities like snapshotFlow{} to workaround that.MR3Y
07/29/2022, 1:11 PMSnapshot.withMutableSnapshot to ensure you're updating state in an isolated thread-safe way before trying to apply this change to be available to other threads. In a @Composable you're not doing that, just make sure to Avoid backwards writesAdam Powell
07/29/2022, 1:14 PMKyant
07/29/2022, 1:16 PMColton Idle
07/29/2022, 1:44 PM