Hello. I was wondering. I have an existing applica...
# compose-web
a
Hello. I was wondering. I have an existing application that uses an MVU architecture and I wanted to look if I can move it to compose-web as a test. So we have an immutable model, a view and update routine. I can easily replace the View with a composeable architecture. The Model will become MutableState<Model> here and the updates will happen via the event handlers which trigger some model update. My question is, will this be performant? As long as I break down my view into composables with arguments they should only recompose when their arguments have changed right? So if I pass down the model elements down to the composables, everything should just be working correctly and 'pretty optimal'?
1
o
Yes, compose's runtime will try to skip irrelevant recompositions https://developer.android.com/jetpack/compose/mental-model#skips https://www.jetpackcompose.app/articles/donut-hole-skipping-in-jetpack-compose - this one can be helpful as well
a
Thanks, I had another question though. I am experimenting with something and I noticed that this works as well:
Copy code
class MyContext(initialModel: Model) {
  var model by mutableStateOf(initialModel)
    private set
}

fun main() {
  with (MyContext(initialize()) {
    renderComposable("root") {
       // some composable which directly reference model
    }
  }
}
So, the composables directly reference
model
so no arguments are passed. However, they recompose brilliantly. Is this all handled by the delegation?
Nevermind: https://developer.android.com/jetpack/compose/state#viewmodels-source-of-truth explains it clearly in the ViewModel part
o
I guess composables read model.value inside, right? If so, then only scopes that read
model.value
should recompose.