if I change a value of some prop inside `@Model` object, will it trigger rerender of a whole "tree"?...
b
if I change a value of some prop inside
@Model
object, will it trigger rerender of a whole "tree"? I mean not only the composable that uses this object, right?
l
@Model
observes only variables, not constants. If a property is constant, what’s the point in observing it? It will never change
a
there is a special observable list implementation -
modelListOf<Foo>()
👌 4
m
but the case of using mutableList with val, the value inside of the list could change
okay, will look into it
l
@Muh Rahmatullah if the
Foo
is also a
Model
it should work
Only if
Foo
changes as you said
m
@Luca Nicoletti I tried that too but it’s not working as well
a
no, it will not work with just mutableList and Model annotated Foo, as there is no changes within Foo, it is a new item added into the list
m
tried the modelListOf and the recompose process now works, thanks @Andrey Kulikov @Luca Nicoletti
l
@Andrey Kulikov That’s what I said:
Only if
Foo
changes
✔️ 1
if
the value inside of the list could change
if it does change, the
@Composable
which refers to the specific instance of
Foo
will be drawn again, right?
a
yes, the composable using specific Model annotated class instance will be automatically recomposed(this will trigger all the required remeasuring/redrawing). if you use it inside measuring lambda - it will be remeasured. if you use inside drawing lambda - redrawn
✔️ 1
l
🙂 Thanks
l
Note thate you don’t need
ModelList
if you just use an immutable list pattern, and instead of using
MutableList
with
add
, you could use
List
with
plus
(list concatenation)
👍 2
@Model will observe assignments to the property itself, but not mutations in the object that is the property (MutableList in your case)
👍 1
m
thanks @Leland Richardson [G]