mon
02/07/2020, 2:46 PM@Model
so that it stops getting updated when the field it is read from changes?Chuck Jazdzewski [G]
02/07/2020, 4:43 PM@Model
changes the FrameManager
(which will be renamed, probably to CompositionManager
) will check if it was read from any compositions and schedule the function that read it to recompose (internally by invalidating the recompose scope created by the function when it called startRestartGroup()
).
The value read from the @Model
is not tracked after the read unless it, itself, is an @Model
object.Leland Richardson [G]
02/07/2020, 5:38 PMclass ValueHolder<T>(var value: T)
@Model MyModel {
// x will cause recompositions
var x = 0
private val yHolder = ValueHolder(0)
var y: Int
get() = yHolder.value
set(field) = yHolder.value = field
}
mutableStateOf
to have a single property that is “tracked”, and the rest of the class won’t be
class MyModel {
var x by mutableStateOf(0)
var y = 0
}
ValueHolder
implement the property delegate operators, you could do the inverse as well:
@Model class MyModel {
var x = 0
var y by ValueHolder(0)
}
mon
02/07/2020, 11:38 PMby mutableStateOf
is what I need