Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasm support #259

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
Expand All @@ -19,4 +20,9 @@ kotlin {
iosArm64()
iosSimulatorArm64()
iosX64()

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<StoreListener<Any, Any, Any, Any>> = 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<StoreListener<Any, Any, Any, Any>>
get() = _globalStoreListeners
@Volatile
var shouldStopOnProcessDeath: Boolean = true
private set

init {
logger { always(IgnoreLog) }
ioDispatchers { Dispatchers.IO }
}
@Volatile
var globalStoreListeners: Set<StoreListener<Any, Any, Any, Any>> = emptySet()
private set

/**
* Configures logging and error handling
Expand All @@ -50,22 +40,22 @@ object ElmslieConfig {
* ```
*/
fun logger(config: (ElmslieLogConfiguration.() -> Unit)) {
ElmslieLogConfiguration().apply(config).build().also { _logger = it }
ElmslieLogConfiguration().apply(config).build().also { logger = it }
}

/**
* Configures CoroutineDispatcher for performing operations in background. Default is
* [Dispatchers.IO]
*/
fun ioDispatchers(builder: () -> CoroutineDispatcher) {
rcmkt marked this conversation as resolved.
Show resolved Hide resolved
_ioDispatchers = builder()
ioDispatchers = builder()
}

fun shouldStopOnProcessDeath(builder: () -> Boolean) {
_shouldStopOnProcessDeath = builder()
shouldStopOnProcessDeath = builder()
}

fun globalStoreListeners(builder: () -> Set<StoreListener<Any, Any, Any, Any>>) {
_globalStoreListeners = builder()
globalStoreListeners = builder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,11 +27,7 @@ class ElmStore<Event : Any, State : Any, Effect : Any, Command : Any>(
private val actor: Actor<Command, out Event>,
storeListeners: Set<StoreListener<Event, State, Effect, Command>>? = 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<Event, Effect, State> {

private val logger = ElmslieConfig.logger
Expand All @@ -46,7 +43,7 @@ class ElmStore<Event : Any, State : Any, Effect : Any, Command : Any>(
storeListeners?.forEach(::add)
}

override val scope = ElmScope("StoreScope")
override val scope = ElmScope("${key}Scope")

override val states: StateFlow<State> = statesFlow.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package money.vivid.elmslie.core.utils

import kotlinx.coroutines.CoroutineDispatcher

internal expect val IoDispatcher: CoroutineDispatcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package money.vivid.elmslie.core.utils

import money.vivid.elmslie.core.store.StateReducer

internal expect fun resolveStoreKey(reducer: StateReducer<*, *, *, *>): String
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Loading