Skip to content

Commit

Permalink
Target WasmJS
Browse files Browse the repository at this point in the history
Signed-off-by: matt-ramotar <[email protected]>
  • Loading branch information
matt-ramotar committed Jun 29, 2024
1 parent 4d32307 commit fd2ffbd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 44 deletions.
7 changes: 0 additions & 7 deletions cache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
id("org.mobilenativefoundation.store.multiplatform")
}

kotlin {

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
7 changes: 0 additions & 7 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
id("org.mobilenativefoundation.store.multiplatform")
}

kotlin {

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
17 changes: 9 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ ktlintGradle = "12.1.0"
jacocoGradlePlugin = "0.8.7"
mavenPublishPlugin = "0.22.0"
moleculeGradlePlugin = "1.2.1"
pagingCompose = "3.3.0-alpha02"
pagingRuntime = "3.2.1"
pagingCompose = "3.3.0"
pagingRuntime = "3.3.0"
spotlessPluginGradle = "6.4.1"
junit = "4.13.2"
kotlinxCoroutines = "1.8.0"
kotlinxSerialization = "1.5.1"
kermit = "1.2.2"
testCore = "1.5.0"
kotlinxSerialization = "1.7.1"
kermit = "2.0.4"
testCore = "1.6.1"
kmmBridge = "0.3.2"
ktlint = "0.39.0"
kover = "0.6.0"
kotlinx-datetime = "0.6.0"
ktlint = "0.39.0"
store = "5.1.0-alpha02"
truth = "1.1.3"
binary-compatibility-validator = "0.15.0-Beta.2"
Expand All @@ -46,7 +47,7 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" }
kotlinx-coroutines-rx2 = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-rx2", version.ref = "kotlinxCoroutines" }
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.4.0" }
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }
molecule-gradle-plugin = { module = "app.cash.molecule:molecule-gradle-plugin", version.ref = "moleculeGradlePlugin" }
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "moleculeGradlePlugin" }
rxjava = { group = "io.reactivex.rxjava2", name = "rxjava", version = "2.2.21" }
Expand All @@ -55,7 +56,7 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor
junit = { group = "junit", name = "junit", version.ref = "junit" }
google-truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
touchlab-kermit = { group = "co.touchlab", name = "kermit", version.ref = "kermit" }
turbine = "app.cash.turbine:turbine:1.0.0"
turbine = "app.cash.turbine:turbine:1.1.0"
binary-compatibility-validator = {module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator"}

[plugins]
Expand Down
2 changes: 1 addition & 1 deletion store/api/android/store.api
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public final class org/mobilenativefoundation/store/store5/StoreReadResponse$NoN
}

public final class org/mobilenativefoundation/store/store5/StoreReadResponseKt {
public static final fun doThrow (Lorg/mobilenativefoundation/store/store5/StoreReadResponse$Error;)Ljava/lang/Void;
public static final fun doThrow (Lorg/mobilenativefoundation/store/store5/StoreReadResponse$Error;)Ljava/lang/Throwable;
}

public abstract class org/mobilenativefoundation/store/store5/StoreReadResponseOrigin {
Expand Down
2 changes: 1 addition & 1 deletion store/api/jvm/store.api
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public final class org/mobilenativefoundation/store/store5/StoreReadResponse$NoN
}

public final class org/mobilenativefoundation/store/store5/StoreReadResponseKt {
public static final fun doThrow (Lorg/mobilenativefoundation/store/store5/StoreReadResponse$Error;)Ljava/lang/Void;
public static final fun doThrow (Lorg/mobilenativefoundation/store/store5/StoreReadResponse$Error;)Ljava/lang/Throwable;
}

public abstract class org/mobilenativefoundation/store/store5/StoreReadResponseOrigin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ sealed class StoreReadResponse<out Output> {
fun requireData(): Output {
return when (this) {
is Data -> value
is Error -> this.doThrow()
is Error -> throw this.doThrow()
else -> throw NullPointerException("there is no data in $this")
}
}
Expand All @@ -86,7 +86,7 @@ sealed class StoreReadResponse<out Output> {
*/
fun throwIfError() {
if (this is Error) {
this.doThrow()
throw this.doThrow()
}
}

Expand Down Expand Up @@ -165,15 +165,16 @@ sealed class StoreReadResponseOrigin {
object Initial : StoreReadResponseOrigin()
}

fun StoreReadResponse.Error.doThrow(): Nothing =
when (this) {
is StoreReadResponse.Error.Exception -> throw error
is StoreReadResponse.Error.Message -> throw RuntimeException(message)
fun StoreReadResponse.Error.doThrow(): Throwable {
return when (this) {
is StoreReadResponse.Error.Exception -> error
is StoreReadResponse.Error.Message -> RuntimeException(message)
is StoreReadResponse.Error.Custom<*> -> {
if (error is Throwable) {
throw error
error
} else {
throw RuntimeException("Non-throwable custom error: $error")
RuntimeException("Non-throwable custom error: $error")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package org.mobilenativefoundation.store.store5.impl

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import org.mobilenativefoundation.store.cache5.Cache
import org.mobilenativefoundation.store.cache5.CacheBuilder
Expand All @@ -19,18 +20,18 @@ import org.mobilenativefoundation.store.store5.Validator
fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcher(
fetcher: Fetcher<Key, Network>,
sourceOfTruth: SourceOfTruth<Key, Network, Output>? = null,
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth)
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth)

fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcherAndSourceOfTruth(
fetcher: Fetcher<Key, Network>,
sourceOfTruth: SourceOfTruth<Key, Network, Output>,
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth)
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth)

fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcherSourceOfTruthAndMemoryCache(
fetcher: Fetcher<Key, Network>,
sourceOfTruth: SourceOfTruth<Key, Network, Output>,
memoryCache: Cache<Key, Output>,
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth, memoryCache)
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth, memoryCache)

fun <Key : Any, Network : Any, Output : Any, Local : Any> storeBuilderFromFetcherSourceOfTruthMemoryCacheAndConverter(
fetcher: Fetcher<Key, Network>,
Expand Down Expand Up @@ -69,12 +70,13 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
return this
}

@OptIn(DelicateCoroutinesApi::class)
override fun build(): Store<Key, Output> =
RealStore<Key, Network, Output, Local>(
RealStore(
scope = scope ?: GlobalScope,
sourceOfTruth = sourceOfTruth,
fetcher = fetcher,
converter = converter ?: defaultConverter(),
converter = converter ?: DefaultConverter(),
validator = validator,
memCache =
memoryCache ?: cachePolicy?.let {
Expand Down Expand Up @@ -134,12 +136,10 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
}
}
}
}

private fun <Network : Any, Local : Any, Output : Any> defaultConverter() =
object : Converter<Network, Local, Output> {
override fun fromOutputToLocal(output: Output): Local =
throw IllegalStateException("non mutable store never call this function")
private class DefaultConverter<Network : Any, Local : Any, Output : Any> : Converter<Network, Local, Output> {
override fun fromOutputToLocal(output: Output): Local = throw IllegalStateException("non mutable store never call this function")

override fun fromNetworkToLocal(network: Network): Local = network as Local
}
override fun fromNetworkToLocal(network: Network): Local = network as Local
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
Expand Down Expand Up @@ -61,6 +60,11 @@ class KotlinMultiplatformConventionPlugin : Plugin<Project> {
nodejs()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

jvmToolchain(17)

targets.all {
Expand Down

0 comments on commit fd2ffbd

Please sign in to comment.