Should we be using `ModelList` in our models? I fo...
# compose
i
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
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
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
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
cool πŸ‘
a
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
nice I am happy with
@Model
its working super nice! :)
πŸ‘ 1