Skip to content

Architecture

Devrath edited this page Oct 17, 2023 · 1 revision

Communication between composable and view-model

Untitled Diagram drawio

  • We keep all the states of the widgets in the view model.
  • States include data that is populated in the widgets and the boolean states
  • We have a public function in the ViewModel that has a sealed class as a parameter where we using which we can invoke a single function with different states and have a when condition to differentiate b/w the different types in view-model.
  • We will have a channel in the view model and we observe the channel as a flow in the composable. We basically send data to the channel from the view model and it gets observed as a flow in composable.
  • We observe the flow in composable wrapped in launchedEffect because it needs to execute only once should not recompose during every recomposition.
Clone this wiki locally