From 5eb7a61b6548ad41bd7172078eac88f1eeee8cae Mon Sep 17 00:00:00 2001 From: Vitaly Pestryakov <34812712+dsvag@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:18:25 +0300 Subject: [PATCH 1/4] add wasm support --- .../main/kotlin/elmslie.kotlin-multiplatform-lib.gradle.kts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build-logic/src/main/kotlin/elmslie.kotlin-multiplatform-lib.gradle.kts b/build-logic/src/main/kotlin/elmslie.kotlin-multiplatform-lib.gradle.kts index 6c6c26d1..17fe5c76 100644 --- a/build-logic/src/main/kotlin/elmslie.kotlin-multiplatform-lib.gradle.kts +++ b/build-logic/src/main/kotlin/elmslie.kotlin-multiplatform-lib.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { kotlin("multiplatform") @@ -19,4 +20,9 @@ kotlin { iosArm64() iosSimulatorArm64() iosX64() + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs() + } } \ No newline at end of file From 3a99b512ecb92029992cd19b61c892b561adec6c Mon Sep 17 00:00:00 2001 From: Vitaly Pestryakov <34812712+dsvag@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:29:45 +0300 Subject: [PATCH 2/4] rework dispatchers usage --- .../elmslie/core/config/ElmslieConfig.kt | 42 +++++++------------ .../vivid/elmslie/core/store/ElmStore.kt | 2 +- .../elmslie/core/utils/DispatcherProvider.kt | 5 +++ .../elmslie/core/utils/DispatcherProvider.kt | 6 +++ .../elmslie/core/utils/DispatcherProvider.kt | 7 ++++ .../elmslie/core/utils/DispatcherProvider.kt | 6 +++ gradle/libs.versions.toml | 4 +- 7 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt create mode 100644 elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt create mode 100644 elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt create mode 100644 elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt diff --git a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/config/ElmslieConfig.kt b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/config/ElmslieConfig.kt index 1393a172..010c2c9f 100644 --- a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/config/ElmslieConfig.kt +++ b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/config/ElmslieConfig.kt @@ -2,40 +2,30 @@ package money.vivid.elmslie.core.config import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.IO import money.vivid.elmslie.core.logger.ElmslieLogConfiguration import money.vivid.elmslie.core.logger.ElmslieLogger import money.vivid.elmslie.core.logger.strategy.IgnoreLog import money.vivid.elmslie.core.store.StoreListener +import money.vivid.elmslie.core.utils.IoDispatcher import kotlin.concurrent.Volatile object ElmslieConfig { @Volatile - private lateinit var _logger: ElmslieLogger + var logger: ElmslieLogger = ElmslieLogConfiguration().apply { always(IgnoreLog) }.build() + private set - @Volatile private lateinit var _ioDispatchers: CoroutineDispatcher - - @Volatile private var _shouldStopOnProcessDeath: Boolean = true - - @Volatile private var _globalStoreListeners: Set> = emptySet() - - val logger: ElmslieLogger - get() = _logger - - val ioDispatchers: CoroutineDispatcher - get() = _ioDispatchers - - val shouldStopOnProcessDeath: Boolean - get() = _shouldStopOnProcessDeath + @Volatile + var ioDispatchers: CoroutineDispatcher = IoDispatcher + private set - val globalStoreListeners: Set> - get() = _globalStoreListeners + @Volatile + var shouldStopOnProcessDeath: Boolean = true + private set - init { - logger { always(IgnoreLog) } - ioDispatchers { Dispatchers.IO } - } + @Volatile + var globalStoreListeners: Set> = emptySet() + private set /** * Configures logging and error handling @@ -50,7 +40,7 @@ object ElmslieConfig { * ``` */ fun logger(config: (ElmslieLogConfiguration.() -> Unit)) { - ElmslieLogConfiguration().apply(config).build().also { _logger = it } + ElmslieLogConfiguration().apply(config).build().also { logger = it } } /** @@ -58,14 +48,14 @@ object ElmslieConfig { * [Dispatchers.IO] */ fun ioDispatchers(builder: () -> CoroutineDispatcher) { - _ioDispatchers = builder() + ioDispatchers = builder() } fun shouldStopOnProcessDeath(builder: () -> Boolean) { - _shouldStopOnProcessDeath = builder() + shouldStopOnProcessDeath = builder() } fun globalStoreListeners(builder: () -> Set>) { - _globalStoreListeners = builder() + globalStoreListeners = builder() } } 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 77bf164c..3087f914 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 @@ -46,7 +46,7 @@ class ElmStore( storeListeners?.forEach(::add) } - override val scope = ElmScope("StoreScope") + override val scope = ElmScope("${key}Scope") override val states: StateFlow = statesFlow.asStateFlow() diff --git a/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt new file mode 100644 index 00000000..e596703b --- /dev/null +++ b/elmslie-core/src/commonMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt @@ -0,0 +1,5 @@ +package money.vivid.elmslie.core.utils + +import kotlinx.coroutines.CoroutineDispatcher + +internal expect val IoDispatcher: CoroutineDispatcher diff --git a/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt b/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt new file mode 100644 index 00000000..8bcbdf79 --- /dev/null +++ b/elmslie-core/src/jvmMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt @@ -0,0 +1,6 @@ +package money.vivid.elmslie.core.utils + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +internal actual val IoDispatcher: CoroutineDispatcher = Dispatchers.IO \ No newline at end of file diff --git a/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt b/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt new file mode 100644 index 00000000..e0d2f43e --- /dev/null +++ b/elmslie-core/src/nativeMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt @@ -0,0 +1,7 @@ +package money.vivid.elmslie.core.utils + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.IO + +internal actual val IoDispatcher: CoroutineDispatcher = Dispatchers.IO \ No newline at end of file diff --git a/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt b/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt new file mode 100644 index 00000000..23f8632e --- /dev/null +++ b/elmslie-core/src/wasmJsMain/kotlin/money/vivid/elmslie/core/utils/DispatcherProvider.kt @@ -0,0 +1,6 @@ +package money.vivid.elmslie.core.utils + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +internal actual val IoDispatcher: CoroutineDispatcher = Dispatchers.Default \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 89cf5c0e..31397483 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] agp = "8.0.2" -coroutines = "1.7.1" +coroutines = "1.8.0" dokka = "1.8.20" -kotlin = "1.9.21" +kotlin = "1.9.23" lifecycle = "2.6.1" [libraries] From 8e4e12293614a2274b57567eb34985528e5a3885 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 3/4] 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 3087f914..09625bbc 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 From 2318e273f6213c0ff6b0cca6e5528de3c6c6f10f Mon Sep 17 00:00:00 2001 From: Vitaly Pestryakov <34812712+dsvag@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:53:09 +0300 Subject: [PATCH 4/4] bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 03bda685..ab16848c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -47,6 +47,6 @@ android.defaults.buildfeatures.shaders=false # # ----- Config ----- # -libraryVersion=3.0.0-alpha10 +libraryVersion=3.0.0-alpha11 pluginVersion=1.0.1 libraryGroup=vivid.money.elmslie