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]