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

Ian Warwick

01/30/2020, 2:04 PM
Should we be using
ModelList
in our models? I found it was the only way to detect changes in a list but not sure if its for use in
@Model
annotated classes 🤔
a

Adam Powell

01/30/2020, 2:08 PM
If you want to detect changes in the content of a mutable list, yes, that's what
ModelList
is for. Alternatively if you're using immutable lists and mutating a reference to said immutable list in a
@Model
class, that will also do what you're after
👍 1
@Model
observation is shallow, it will only make changes to the class annotated with it observable. If you change a plain old mutable object that happens to be held in a
val
in an
@Model
class, that change won't be tracked.
👍 1
But it's perfectly fine for
@Model
objects to reference one another
👍 1
i

Ian Warwick

01/30/2020, 2:14 PM
Thankyou @Adam Powell! I guess I was confused because it was in the
.frames
package and that seemed a bit low level package for end user 🙂
If you want to detect changes in the content of a mutable list, yes, that's what
ModelList
is for. Alternatively if you're using immutable lists and mutating a reference to said immutable list in a
@Model
class, that will also do what you're after
Cool, can that reference be a
MutableList
or must it be a
ModelList
when mutating the ref?
a

Adam Powell

01/30/2020, 2:19 PM
We're thinking about naming for all of this stuff. The word, "snapshot" keeps coming back up. "Model" is uncomfortably generic and, "frames" describes the mechanism but not really the usage, and when it appears so close to UI code it's hard not to think
FrameLayout
on some level
👍 1
The reference can be whatever you want, but if you change a mutable object that isn't itself
@Model
, compose won't know about it unless you tell it explicitly
👍 1
i

Ian Warwick

01/30/2020, 2:20 PM
cool 👍
a

Adam Powell

01/30/2020, 2:20 PM
And using anything other than
@Model
(or immutable objects) is going to get very complicated in the presence of some of our multithreading ambitions
i

Ian Warwick

01/30/2020, 2:21 PM
nice I am happy with
@Model
its working super nice! :)
👍 1
2 Views