Skip to content
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
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
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,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 = "0.6.1" }
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 @@ -56,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.2.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 @@ -378,7 +378,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 @@
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 @@
*/
fun throwIfError() {
if (this is Error) {
this.doThrow()
throw this.doThrow()
}
}

Expand Down Expand Up @@ -165,15 +165,16 @@
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: doThrow name isn't applicable anymore here.

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

Check warning on line 174 in store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L174 was not covered by tests
} else {
throw RuntimeException("Non-throwable custom error: $error")
RuntimeException("Non-throwable custom error: $error")

Check warning on line 176 in store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/StoreReadResponse.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L176 was not covered by tests
}
}
}
}
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 @@
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)

Check warning on line 34 in store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L34 was not covered by tests

fun <Key : Any, Network : Any, Output : Any, Local : Any> storeBuilderFromFetcherSourceOfTruthMemoryCacheAndConverter(
fetcher: Fetcher<Key, Network>,
Expand Down Expand Up @@ -69,12 +70,13 @@
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 @@
}
}
}
}

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")

Check warning on line 142 in store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStoreBuilder.kt

View check run for this annotation

Codecov / codecov/patch

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

Added line #L142 was not covered by tests

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,6 +17,7 @@ import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

Expand Down Expand Up @@ -57,6 +58,11 @@ class KotlinMultiplatformConventionPlugin : Plugin<Project> {
nodejs()
}

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

jvmToolchain(11)

targets.all {
Expand Down