Anyone used `getViewModel()` in a composable, whe...
# koin
n
Anyone used
getViewModel()
in a composable, where the parameters of the vm are subject to change?
a
you mean, your ViewModel instance is always the same?
n
yes
a
I believe your ViewModel instance won’t change, you’ll request always the same instance
to confirm
injection params are used for instance creation
then it’s used 1st time
n
yupp, these issues can be solved by modifying the state of the current ViewModel instance. However I think it may go against the whole recomposition pattern. Not sure though how compose handles this under the hood and if it can be implemented in koin. Is there a possibility to consider checking the parameters, before retrieving the instance?
a
consider checking the parameters, before retrieving the instance
wdyt?
n
I mean I’m not sure why the same instance is retrieved. Just to make sure I’ve understood you, within the same scope if you try to get an instance of a VM twice with different parameters, the second call will get you the already created instance (with the first parameter). Right?
Basically I meant if there is a way of checking the parameters (given with
parametersOf
) and if different regardless of scope return a new instance. Or is this something that’s solved by the ViewModelProvider and is OoS for Koin?
@arnaud.giuliani I’ve did a bit of digging:
We should create a public API that allows developers to conveniently scope ViewModel to composition lifecycle.
https://issuetracker.google.com/issues/165642391
a
interesting 👍