From 2fd69ee0a7a037e9b589d35b23caf1d3a200d5b7 Mon Sep 17 00:00:00 2001 From: Vitaly Pestryakov <34812712+dsvag@users.noreply.github.com> Date: Tue, 23 Apr 2024 00:40:19 +0400 Subject: [PATCH] fix JS unsupported api --- .../kotlin/money/vivid/elmslie/core/store/ElmStore.kt | 7 ++----- .../money/vivid/elmslie/core/utils/ResolveStoreKey.kt | 5 +++++ .../money/vivid/elmslie/core/utils/ResolveStoreKey.kt | 8 ++++++++ .../money/vivid/elmslie/core/utils/ResolveStoreKey.kt | 8 ++++++++ .../money/vivid/elmslie/core/utils/ResolveStoreKey.kt | 8 ++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt create mode 100644 elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt create mode 100644 elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt create mode 100644 elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt diff --git a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/store/ElmStore.kt b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/store/ElmStore.kt index b5b440b7..e694fcd4 100644 --- a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/store/ElmStore.kt +++ b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/store/ElmStore.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import money.vivid.elmslie.core.ElmScope import money.vivid.elmslie.core.config.ElmslieConfig +import money.vivid.elmslie.core.utils.resolveStoreKey @Suppress("TooGenericExceptionCaught") @OptIn(ExperimentalCoroutinesApi::class) @@ -26,11 +27,7 @@ class ElmStore( private val actor: Actor, storeListeners: Set>? = null, override val startEvent: Event? = null, - private val key: String = - (reducer::class.qualifiedName ?: reducer::class.simpleName).orEmpty().replace( - "Reducer", - "Store", - ), + private val key: String = resolveStoreKey(reducer), ) : Store { private val logger = ElmslieConfig.logger diff --git a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt new file mode 100644 index 00000000..34ead988 --- /dev/null +++ b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt @@ -0,0 +1,5 @@ +package money.vivid.elmslie.core.utils + +import money.vivid.elmslie.core.store.StateReducer + +internal expect fun resolveStoreKey(reducer: StateReducer<*, *, *, *>): String \ No newline at end of file diff --git a/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt b/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt new file mode 100644 index 00000000..a31f58ab --- /dev/null +++ b/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt @@ -0,0 +1,8 @@ +package money.vivid.elmslie.core.utils + +import money.vivid.elmslie.core.store.StateReducer + +internal actual fun resolveStoreKey(reducer: StateReducer<*, *, *, *>): String = + (reducer::class.qualifiedName ?: reducer::class.simpleName) + .orEmpty() + .replace("Reducer", "Store") \ No newline at end of file diff --git a/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt b/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt new file mode 100644 index 00000000..36053259 --- /dev/null +++ b/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt @@ -0,0 +1,8 @@ +package money.vivid.elmslie.core.utils + +import money.vivid.elmslie.core.store.StateReducer + +internal actual fun resolveStoreKey(reducer: StateReducer<*, *, *, *>): String = + (reducer::class.qualifiedName ?: reducer::class.simpleName) + .orEmpty() + .replace("Reducer", "Store") diff --git a/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt b/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt new file mode 100644 index 00000000..4a9ad0bb --- /dev/null +++ b/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/ResolveStoreKey.kt @@ -0,0 +1,8 @@ +package money.vivid.elmslie.core.utils + +import money.vivid.elmslie.core.store.StateReducer + +internal actual fun resolveStoreKey(reducer: StateReducer<*, *, *, *>): String = + reducer::class.simpleName + .orEmpty() + .replace("Reducer", "Store") \ No newline at end of file