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

Cody Engel

10/24/2019, 5:00 AM
Would the issue tracker be a good spot to make requests? I was hoping to do something like this:
Copy code
@Model
class Name(var name: String = "Android") : ViewModel()
But inheritance isn’t currently supported for Model objects. We currently use LiveData a lot today but with Compose it seems like unnecessary overhead.
t

themishkun

10/24/2019, 6:27 AM
Imagine how many subtile bugs inheritance would cause when combined with clever stuff
@Model
tries to do to register observables. Do you really want that? Just use composition over inheritance and smack that
@Model
as a property of your ViewModel. But before that, try to think: do you even need a ViewModel in the first place?
☝️ 5
l

Luca Nicoletti

10/24/2019, 7:42 AM
Imho: no, not anymore 😛
g

George Mount

10/24/2019, 2:55 PM
Many devs have existing systems that they will have to integrate with. In the "What's new" talk, Adam spoke about a future option (he had an effect function) where you'll be able to just observe LiveData objects. It should be just a few lines of code to write a LiveData observer that causes recomposition when the value changes.
c

Cody Engel

10/24/2019, 3:27 PM
Why would you not use ViewModel for this? Compose doesn’t save state across configuration changes, ViewModel does.
Model seems to keep track of public properties on a class so allowing for inheritance seems like it would be fine. Asking everyone to annotate with model when that’s the desired default behavior is going to get clumsy and prone to errors
c

Chuck Jazdzewski [G]

10/24/2019, 5:07 PM
Supporting inheritance for
@Model
classes is in the plan but is not currently supported.
l

Luca Nicoletti

10/24/2019, 5:08 PM
Any particular reason why you’re now blocking it?
c

Chuck Jazdzewski [G]

10/24/2019, 5:10 PM
It requires changes in the
@Model
lowering transform to support inheritance. The state record needs to inherit from the ancestor state record which is admittedly not that difficult to implement but I have not gotten to it yet.
c

Cody Engel

10/24/2019, 5:44 PM
Yeah talking with everyone today during the sandbox was really helpful. So far there have been work arounds for any wall I’ve hit which is really reassuring and I’m excited to see how this progresses
t

themishkun

10/24/2019, 9:45 PM
@Cody Engel Activity is killed on config changes because current ui toolkit is not reactive. But with compose all you need to do is to change some ambients and trigger recomposition to switch language/theme/configuration. So you can just enable manual handling of config changes and forget about ViewModel
c

Cody Engel

10/24/2019, 9:58 PM
How would you write unit tests for that?
I guess it feels weird to abandon ViewModel, it worked well should still work fine for Compose.
t

themishkun

10/25/2019, 5:46 AM
@Cody Engel Just as you would write unit tests for anything. State update functions can be just functions, you know
3 Views