Mark
04/15/2024, 1:05 PMKoin.getAll()
always a single new instance is returned (and none of the existing instances). Is this a bug, or is there another way to do this?arnaud.giuliani
04/15/2024, 1:50 PMMark
04/15/2024, 1:52 PMarnaud.giuliani
04/15/2024, 1:55 PMMark
04/15/2024, 1:58 PMMark
04/15/2024, 2:00 PMarnaud.giuliani
04/15/2024, 2:20 PMMark
04/15/2024, 2:29 PMViewModelStore
(since composables have access to LocalViewModelStoreOwner
), but unfortunately the methods I want to use are restricted to the library group. Any tips?arnaud.giuliani
04/15/2024, 2:32 PMresolveViewModel
from Koinarnaud.giuliani
04/15/2024, 2:32 PMMark
04/15/2024, 2:46 PMfun ViewModelStore.resolveViewModel(key: String): DialogViewModel {
val provider = ViewModelProvider(this, object : ViewModelProvider.Factory { })
return provider[key, DialogViewModel::class.java]
}
Note: I’m assuming it’s okay to pass this empty instance of Factory
(which would throw an exception if one of the create methods is called). This avoids the need for KoinScope
.
Update: oh actually, this only works for my use case, since I can detect when a view model is the last instance and so never call with a non-existent key).Mark
04/15/2024, 2:50 PMarnaud.giuliani
04/15/2024, 3:45 PMMark
04/15/2024, 4:03 PM