Title
k

Kirill Grouchnikov

12/23/2020, 4:15 PM
Are `ViewModel`s a thing in Compose Desktop world? Or are we using https://github.com/arkivanov/Decompose for something simple like an observable list of data items?
j

Javier

12/23/2020, 4:36 PM
cc @Arkadii Ivanov
a

Arkadii Ivanov

12/23/2020, 4:48 PM
Not sure about Compose Desktop itself, but Decompose provides ability to retain instances (e.g. over configuration changes in Android). Check out the readme.
a

Andrey Kulikov

12/23/2020, 6:59 PM
as there is no such thing as configuration changes in simplest cases you can just use
remember
and create your ViewModel like holder for any logic there
a

Arkadii Ivanov

12/23/2020, 7:06 PM
But there is. You may want to retain an instance over "scope" recreation. In Android it could be configuration changes. In other platforms it could be whatever you consider as scope. So it actually makes sense in common, and this is what Decompose does.
r

Ruckus

12/24/2020, 4:32 PM
@Arkadii Ivanov Out of curiosity, do you have an example of what that might be? I'm having a hard time thinking of anything that would seem to be equivalent.
a

Arkadii Ivanov

12/24/2020, 4:51 PM
From my point of view, it is very abstract. So there is a navigation back stack of e.g. screens. Each screen has its own scope. Normally screens are created when pushed to the back stack. And destroyed when popped. But there is a possible use case: the back stack can be recreated, for whatever reason. You may want to retain some objects over such recreations, e.g. a view model. Possible scenarios: system locale change, system theme change, display scale factor, etc.. Anyway, Compose Desktop is multiplatform. So unless recreation is a thing at least in Android, it would be good to have this in common.
r

Ruckus

12/24/2020, 4:53 PM
Huh, interesting. I'll have to think on it more. Thanks!
👍 1