Confused. I was going to start adding some `@Model...
# compose
t
Confused. I was going to start adding some `@Model`to my little demo learning playgrounds, but the IDE doesn't recognize that annotation. Nor does it offer an import. Is this something that is either too new or perhaps old/deprecated?
s
Where did you see this
@Model
annotation?
f
That is really really old Compose concept if I remember correctly. Got eventually replaced by
mutableStateOf()
but I never used it. I just remember it from the first presentation at Google I/O. That didn't even get to Compose 1.0 👴
k
So new, its date stamp overflowed all the way back to 2019(ish) 🙂
s
Oh damn, that’s hella old. Even this post https://adambennett.dev/2019/10/jetpack-compose-now-on-maven/ from 3 years ago there’s someone in the comments asking “So... @Model annotation right now isn’t it working?“. Where did you even get this information Travis?
t
Thanks. That's what I suspected. I hate the internet. 😄
If you're a "new to the territory" guy, and you don't need to "transition" from MVVM or whatever and do halfway implementations, what is the story for bridging a domain model with one's app? Googling for this kind of stuff turns up so many of those "hella old" hits that you can't tell the wheat from the chaff
f
Just stick to official documentation imho. When you get the basics, you can start wildly googling 😅
t
I guess here's the bridge I'm struggling with: I've read (and reread) an official doc: https://developer.android.com/jetpack/compose/state I have in my mind a heirarchical object model that models my "domain" (real world agricultural devices) synced via BLE/MQTT. I don't get a clear picture when I read that official doc, how I'mg going to tweak my model objects so that recomposition happens when it ought to. Do I just start putting anything that changes in a LiveData and go that route?
Or is it as simple as "just use mutableState" in your domain model fields that would trigger changes?
s
Your previous message feels like a bit too much for me to understand and answer confidently. But for your last one, you can either save stuff inside MutableState directly. Or even a
StateFlow
where you then read it by converting it to state (with .collectAsState() or .collectAsStateWithLifecycle()) and yes, it should just reflect those changes in your UI. But again, I think that what Filip is saying is your best bet. Get familiar with the basic concepts first, and then it will be quite a lot easier to figure out the rest.