Tlaster / PreCompose

Compose Multiplatform Navigation && State Management

Home Page:https://tlaster.github.io/PreCompose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] koinViewModel in precompose-koin not consistent across platform

reginaldlouis opened this issue · comments

In precompose-koin version 1.6, for jvm, just calling koinViewModel<BudgetViewModel>() work, but for wasmJs I get this error:

No value passed for parameter 'vmClass'

When digging into precompose-koin, I can see that koinViewModel has 2 different signatures.

In commonMain/kotlin/moe/tlaster/precompose/koin/Koin.kt the signature is:

fun <T : ViewModel> koinViewModel(
    vmClass: KClass<T>,
    qualifier: Qualifier? = null,
    stateHolder: StateHolder = checkNotNull(LocalStateHolder.current) {
        "No StateHolder was provided via LocalStateHolder"
    },
    key: String? = null,
    scope: Scope = LocalKoinScope.current,
    parameters: ParametersDefinition? = null,
): T

And in jvmAndroidMain/kotlin/moe/tlaster/precompose/koin/Koin.jvmAndroid.kt the signature is:

inline fun <reified T : ViewModel> koinViewModel(
    qualifier: Qualifier? = null,
    stateHolder: StateHolder = checkNotNull(LocalStateHolder.current) {
        "No StateHolder was provided via LocalStateHolder"
    },
    key: String? = null,
    scope: Scope = LocalKoinScope.current,
    noinline parameters: ParametersDefinition? = null,
): T

No need to pass a vmClass: KClass<T> parameter. Why not have a consitent api across platform?

Because there's a bug for Kotlin/Native with Compose: JetBrains/compose-multiplatform#3147, the doc dose mention this in here.

Looks like the bug was fixed?
JetBrains/compose-multiplatform#3147

Looks like the bug was fixed? JetBrains/compose-multiplatform#3147

Seems like the fix is included in compose compiler 1.5.10.2, so we can get generic inline composable function now!

@Tlaster seems like androidx now supports kmp lifecycle, navigation and viewmodel (at least in the alphas). Plans to wind down this library?

@Tlaster seems like androidx now supports kmp lifecycle, navigation and viewmodel (at least in the alphas). Plans to wind down this library?

I haven't decided yet, but since Google and Jetbrains officially releasing ViewModel and Navigation for multiplatform, maybe PreCompose have done its job.