Are `ViewModel`s a thing in Compose Desktop world?...
# compose-desktop
k
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
cc @Arkadii Ivanov
a
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
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
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
@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
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
Huh, interesting. I'll have to think on it more. Thanks!
👍 1
386 Views