robnik
12/15/2020, 10:37 PM@Composable fun Things(model: MyViewModel) {
val mutableThing = model.thing
mutableThing.addChangeListener { recomposeThisStuff() }
Text("${mutableThing.size} ...")
So "model.thing" may always be the same reference/object. But it changes internally.robnik
12/15/2020, 10:41 PMlen
12/15/2020, 10:42 PMthing
to a MutableState
in your ViewModel, and just do Text("${model.thing.size}")
len
12/15/2020, 10:43 PMrobnik
12/15/2020, 10:56 PMmodel.thing
never changes. As far as Compose is concerned, that mutable state is not changing. Am I supposed to observe the object and then call thing.value = thing.value
to try and trigger a recompose?robnik
12/15/2020, 10:58 PMlen
12/16/2020, 12:24 AMlen
12/16/2020, 12:29 AMlen
12/16/2020, 12:31 AMrobnik
12/16/2020, 1:49 AMrobnik
12/16/2020, 1:56 AMrobnik
12/16/2020, 2:06 AMmutableStateOf()
. So this one line change makes my example work. var thing1: Thing by mutableStateOf(Thing(), neverEqualPolicy())
. Seems odd though, so I still wonder if there is a better way.Adam Powell
12/16/2020, 3:42 PMThing
, using neverEqualPolicy
is fine thererobnik
12/16/2020, 8:31 PMThing
? Should I try to make it completely immutable, or is there another way to make mutable objects that works better with Compose?