I don't know if I understood 100% of model struct,...
# compose
b
I don't know if I understood 100% of model struct, are we able to create a model with immutable values and the compiler considers the model itself as an observable or only mutable fields are supported?
l
you can have immutable fields on the model but only the mutable fields will be the things that are “observed” in this way. As a result, a fully immutable class (ie, all val properties) annotated as @Model is somewhat meaningless. Not sure if that answers your question though
b
Yeah this answer my question, thank you! I ask that because I don't know if I'm comfortable to use mutable models, but I also don't know if an immutable state api should be implemented on compose lib side because its possible performance problems.
l
fwiw, if you’re already using immutable data structures, you should continue to do so. compose will work great with immutable types. Sometimes it is very difficult to move things over to this paradigm, so we wanted to make sure we had an answer for people that was better than “move to immutable types or else you’re doing it wrong”. (slightly more detailed answer on this can be found here: https://www.reddit.com/r/androiddev/comments/bmf57d/declarative_ui_patterns_google_io19/emxpixw?utm_source=share&utm_medium=web2x)
b
Nice! I was trying to find your motivation for this, thank you!