https://kotlinlang.org logo
#compose
Title
# compose
b

Bruno_

11/18/2019, 10:03 PM
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

Luca Nicoletti

11/20/2019, 12:18 PM
@Model
observes only variables, not constants. If a property is constant, what’s the point in observing it? It will never change
a

Andrey Kulikov

11/20/2019, 12:19 PM
there is a special observable list implementation -
modelListOf<Foo>()
👌 4
m

Muh Rahmatullah

11/20/2019, 12:19 PM
but the case of using mutableList with val, the value inside of the list could change
okay, will look into it
l

Luca Nicoletti

11/20/2019, 12:20 PM
@Muh Rahmatullah if the
Foo
is also a
Model
it should work
Only if
Foo
changes as you said
m

Muh Rahmatullah

11/20/2019, 12:23 PM
@Luca Nicoletti I tried that too but it’s not working as well
a

Andrey Kulikov

11/20/2019, 12:33 PM
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

Muh Rahmatullah

11/20/2019, 12:36 PM
tried the modelListOf and the recompose process now works, thanks @Andrey Kulikov @Luca Nicoletti
l

Luca Nicoletti

11/20/2019, 12:43 PM
@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

Andrey Kulikov

11/20/2019, 12:46 PM
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

Luca Nicoletti

11/20/2019, 12:47 PM
🙂 Thanks
l

Leland Richardson [G]

11/20/2019, 5:22 PM
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

Muh Rahmatullah

11/21/2019, 3:41 AM
thanks @Leland Richardson [G]
3 Views