Koin 2.2.0-alpha-1 is out ... Now you can use KOin...
# koin
a
Koin 2.2.0-alpha-1 is out ... Now you can use KOin with Kotlin 1.4 👍
🎉 9
m
is there any docs on it or change log i can't find any
a
changelog is updated
m
Thanks
z
Does this version support multiplatform or is that limited to the 3.0.x artifacts?
a
@arnaud.giuliani how big are the existing API changes in 2.2.0-alpha1 and how
alpha
it is compared to 2.1.6?
a
mostly ViewModel API & Scope API changes
better consistent API + fixes
checkModules can now check all your modules even with injection params
(it uses default values)
a
@arnaud.giuliani weird that in 2.2.0 and Kotlin 1.4.0 the last item in
parametersOf()
must be cast to
Any
and could not be nullable.
Type mismatch: inferred type is String? but Any was expected
Also could you tell me if I have updated a ViewModel instantiation correctly? I have replaced the old code
Copy code
viewModel = lifecycleScope.getViewModel<FormsViewModel>(this) {
                parametersOf(
                    intent?.getBooleanExtra(ProcessHelper.IntentParamShouldReset, false) ?: false,
                    intent?.getStringExtra("processName")
                )
            }
to
Copy code
val viewModel = scope.getViewModel<FormsViewModel>(null, emptyState(),
                { ViewModelOwner.from(viewModelStore) }, parameters = {
                    parametersOf(
                        intent?.getBooleanExtra(ProcessHelper.IntentParamShouldReset, false)
                            ?: false,
                        intent?.getStringExtra("processName") as Any,
                    )
                }
            )
Old implementation looks much more cleaner than the current one and also there are many
viewModel(...)
methods, that I found confusing in terms of which I should use. If you could provide some suggestion or samples how it should be used, that will be very much appreciated. Will describe what I want to achieve in case you might know the easier way 😄
Copy code
I have an activity that initiates view model and all the fragments and child fragments inside that activity are able to access this view model if needed via Activity. And during activity lifecycle the same instance of ViewModel is delivered to fragments via `getSharedViewModel` call.
In 2.1.6 I done this via activity `lifecycle` 
module definition looks like this:
scope(named<MyActivity>()) {
    viewModel { (intent: Intent?) -> MyViewModel(get(), get(), intent) }
}
a
@aipok you mean having nullable param injection 🤔 ?
a
Yes, this is needed in order to use same component but with different options. You might have it in one case and might not in the other case. I was thinking, that it should be possible to make multiple definitions with different parameters, but it wasn’t needed previously.