Skip to content

Commit f588cca

Browse files
authored
Target Wasm JS (#646)
Signed-off-by: Matt Ramotar <[email protected]>
1 parent bd0ce82 commit f588cca

File tree

8 files changed

+30
-37
lines changed

8 files changed

+30
-37
lines changed

cache/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
2-
31
plugins {
42
id("org.mobilenativefoundation.store.multiplatform")
53
}
64

75
kotlin {
86

9-
@OptIn(ExperimentalWasmDsl::class)
10-
wasmJs {
11-
nodejs()
12-
}
13-
147
sourceSets {
158
val commonMain by getting {
169
dependencies {

core/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
2-
31
plugins {
42
id("org.mobilenativefoundation.store.multiplatform")
53
}
64

75
kotlin {
86

9-
@OptIn(ExperimentalWasmDsl::class)
10-
wasmJs {
11-
nodejs()
12-
}
13-
147
sourceSets {
158
val commonMain by getting {
169
dependencies {

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-
4747
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
4848
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutines" }
4949
kotlinx-coroutines-rx2 = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-rx2", version.ref = "kotlinxCoroutines" }
50-
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.4.0" }
50+
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version = "0.6.1" }
5151
molecule-gradle-plugin = { module = "app.cash.molecule:molecule-gradle-plugin", version.ref = "moleculeGradlePlugin" }
5252
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "moleculeGradlePlugin" }
5353
rxjava = { group = "io.reactivex.rxjava2", name = "rxjava", version = "2.2.21" }
@@ -56,7 +56,7 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor
5656
junit = { group = "junit", name = "junit", version.ref = "junit" }
5757
google-truth = { group = "com.google.truth", name = "truth", version.ref = "truth" }
5858
touchlab-kermit = { group = "co.touchlab", name = "kermit", version.ref = "kermit" }
59-
turbine = "app.cash.turbine:turbine:1.0.0"
59+
turbine = "app.cash.turbine:turbine:1.2.0"
6060
binary-compatibility-validator = {module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator"}
6161

6262
[plugins]

store/api/android/store.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public final class org/mobilenativefoundation/store/store5/StoreReadResponse$NoN
378378
}
379379

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

384384
public abstract class org/mobilenativefoundation/store/store5/StoreReadResponseOrigin {

store/api/jvm/store.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public final class org/mobilenativefoundation/store/store5/StoreReadResponse$NoN
371371
}
372372

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

377377
public abstract class org/mobilenativefoundation/store/store5/StoreReadResponseOrigin {

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ sealed class StoreReadResponse<out Output> {
7575
fun requireData(): Output {
7676
return when (this) {
7777
is Data -> value
78-
is Error -> this.doThrow()
78+
is Error -> throw this.doThrow()
7979
else -> throw NullPointerException("there is no data in $this")
8080
}
8181
}
@@ -86,7 +86,7 @@ sealed class StoreReadResponse<out Output> {
8686
*/
8787
fun throwIfError() {
8888
if (this is Error) {
89-
this.doThrow()
89+
throw this.doThrow()
9090
}
9191
}
9292

@@ -165,15 +165,16 @@ sealed class StoreReadResponseOrigin {
165165
object Initial : StoreReadResponseOrigin()
166166
}
167167

168-
fun StoreReadResponse.Error.doThrow(): Nothing =
169-
when (this) {
170-
is StoreReadResponse.Error.Exception -> throw error
171-
is StoreReadResponse.Error.Message -> throw RuntimeException(message)
168+
fun StoreReadResponse.Error.doThrow(): Throwable {
169+
return when (this) {
170+
is StoreReadResponse.Error.Exception -> error
171+
is StoreReadResponse.Error.Message -> RuntimeException(message)
172172
is StoreReadResponse.Error.Custom<*> -> {
173173
if (error is Throwable) {
174-
throw error
174+
error
175175
} else {
176-
throw RuntimeException("Non-throwable custom error: $error")
176+
RuntimeException("Non-throwable custom error: $error")
177177
}
178178
}
179179
}
180+
}

store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.mobilenativefoundation.store.store5.impl
44

55
import kotlinx.coroutines.CoroutineScope
6+
import kotlinx.coroutines.DelicateCoroutinesApi
67
import kotlinx.coroutines.GlobalScope
78
import org.mobilenativefoundation.store.cache5.Cache
89
import org.mobilenativefoundation.store.cache5.CacheBuilder
@@ -19,18 +20,18 @@ import org.mobilenativefoundation.store.store5.Validator
1920
fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcher(
2021
fetcher: Fetcher<Key, Network>,
2122
sourceOfTruth: SourceOfTruth<Key, Network, Output>? = null,
22-
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth)
23+
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth)
2324

2425
fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcherAndSourceOfTruth(
2526
fetcher: Fetcher<Key, Network>,
2627
sourceOfTruth: SourceOfTruth<Key, Network, Output>,
27-
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth)
28+
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth)
2829

2930
fun <Key : Any, Network : Any, Output : Any> storeBuilderFromFetcherSourceOfTruthAndMemoryCache(
3031
fetcher: Fetcher<Key, Network>,
3132
sourceOfTruth: SourceOfTruth<Key, Network, Output>,
3233
memoryCache: Cache<Key, Output>,
33-
): StoreBuilder<Key, Output> = RealStoreBuilder<Key, Network, Output, Network>(fetcher, sourceOfTruth, memoryCache)
34+
): StoreBuilder<Key, Output> = RealStoreBuilder(fetcher, sourceOfTruth, memoryCache)
3435

3536
fun <Key : Any, Network : Any, Output : Any, Local : Any> storeBuilderFromFetcherSourceOfTruthMemoryCacheAndConverter(
3637
fetcher: Fetcher<Key, Network>,
@@ -69,12 +70,13 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
6970
return this
7071
}
7172

73+
@OptIn(DelicateCoroutinesApi::class)
7274
override fun build(): Store<Key, Output> =
73-
RealStore<Key, Network, Output, Local>(
75+
RealStore(
7476
scope = scope ?: GlobalScope,
7577
sourceOfTruth = sourceOfTruth,
7678
fetcher = fetcher,
77-
converter = converter ?: defaultConverter(),
79+
converter = converter ?: DefaultConverter(),
7880
validator = validator,
7981
memCache =
8082
memoryCache ?: cachePolicy?.let {
@@ -134,12 +136,10 @@ internal class RealStoreBuilder<Key : Any, Network : Any, Output : Any, Local :
134136
}
135137
}
136138
}
139+
}
137140

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

143-
override fun fromNetworkToLocal(network: Network): Local = network as Local
144-
}
144+
override fun fromNetworkToLocal(network: Network): Local = network as Local
145145
}

tooling/plugins/src/main/kotlin/org/mobilenativefoundation/store/tooling/plugins/KotlinMultiplatformConventionPlugin.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.gradle.kotlin.dsl.configure
1717
import org.gradle.kotlin.dsl.get
1818
import org.gradle.kotlin.dsl.withType
1919
import org.jetbrains.dokka.gradle.DokkaTask
20+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2021
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
2122
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
2223

@@ -57,6 +58,11 @@ class KotlinMultiplatformConventionPlugin : Plugin<Project> {
5758
nodejs()
5859
}
5960

61+
@OptIn(ExperimentalWasmDsl::class)
62+
wasmJs {
63+
nodejs()
64+
}
65+
6066
jvmToolchain(11)
6167

6268
targets.all {

0 commit comments

Comments
 (0)