Skip to content

Commit

Permalink
disable persisting states on wasm for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Apr 16, 2024
1 parent 7baf428 commit dd8618f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Config {
const val majorRelease = 2
const val minorRelease = 5
const val patch = 0
const val postfix = "-alpha06" // include dash (-)
const val postfix = "-alpha07" // include dash (-)
const val majorVersionName = "$majorRelease.$minorRelease.$patch"
const val versionName = "$majorVersionName$postfix"
const val url = "https://github.com/respawn-app/FlowMVI"
Expand Down
5 changes: 5 additions & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ kotlin {
nodejs()
browser()
binaries.library()
applyBinaryen()
}
jvm("desktop")

Expand All @@ -45,6 +46,7 @@ kotlin {

sourceSets {
val desktopMain by getting
val wasmJsMain by getting

configurations.all {
exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-coroutines-android")
Expand Down Expand Up @@ -97,6 +99,9 @@ kotlin {
androidMain.dependencies {
implementation(applibs.koin.android)
}
wasmJsMain.dependencies {
implementation(applibs.okio.fakefsys)
}
} // sets
}
android {
Expand Down
2 changes: 2 additions & 0 deletions sample/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ koin = "3.6.0-wasm-alpha2"
kmputils = "1.3.2"
material = "1.12.0-rc01"
activity = "1.9.0-rc01"
okio = "3.9.0"
splashscreen = "1.1.0-rc01"
#codehighlights = "0.8.0"

Expand All @@ -21,6 +22,7 @@ koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-android-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
okio-fakefsys = { module = "com.squareup.okio:okio-fakefilesystem", version.ref = "okio" }
koin-test = { module = "io.insert-koin:koin-test", version.ref = "koin" }
apiresult = { module = "pro.respawn.apiresult:core", version.ref = "apiresult" }
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "activity" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import pro.respawn.flowmvi.savedstate.api.NullRecover
import pro.respawn.flowmvi.savedstate.api.Saver
import pro.respawn.flowmvi.savedstate.dsl.CompressedFileSaver
import pro.respawn.flowmvi.savedstate.dsl.JsonSaver
import pro.respawn.flowmvi.savedstate.dsl.NoOpSaver
import pro.respawn.flowmvi.savedstate.plugins.saveStatePlugin

internal class DefaultStoreConfiguration(
Expand All @@ -29,11 +30,13 @@ internal class DefaultStoreConfiguration(
override fun <S : MVIState> saver(
serializer: KSerializer<S>,
fileName: String,
): Saver<S> = CompressedFileSaver(
dir = cacheDir,
fileName = "$fileName.gz",
recover = NullRecover
).let { JsonSaver(json, serializer, it) }
): Saver<S> {
return CompressedFileSaver(
dir = cacheDir ?: return NoOpSaver(),
fileName = "$fileName.gz",
recover = NullRecover
).let { JsonSaver(json, serializer, it) }
}

override operator fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.invoke(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class SavedStateContainer(
// can also be injected, defined here for illustration purposes
// see "StoreConfiguration" for injection setup
serializeState(
dir = fileManager.cacheDir("state"),
dir = fileManager.cacheDir("state") ?: "",
json = json,
serializer = DisplayingInput.serializer(),
recover = NullRecover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -20,6 +21,7 @@ import org.jetbrains.compose.resources.stringResource
import pro.respawn.flowmvi.api.IntentReceiver
import pro.respawn.flowmvi.compose.dsl.requireLifecycle
import pro.respawn.flowmvi.compose.dsl.subscribe
import pro.respawn.flowmvi.sample.BuildFlags
import pro.respawn.flowmvi.sample.arch.di.container
import pro.respawn.flowmvi.sample.features.savedstate.SavedStateFeatureState.DisplayingInput
import pro.respawn.flowmvi.sample.features.savedstate.SavedStateIntent.ChangedInput
Expand All @@ -31,6 +33,8 @@ import pro.respawn.flowmvi.sample.ui.widgets.CodeText
import pro.respawn.flowmvi.sample.ui.widgets.RScaffold
import pro.respawn.flowmvi.sample.ui.widgets.RTextInput
import pro.respawn.flowmvi.sample.ui.widgets.TypeCrossfade
import pro.respawn.flowmvi.sample.util.Platform
import pro.respawn.flowmvi.sample.util.platform

private const val Description = """
Saved state plugin allows you to persist a state of a store into a file or other place in about 5 lines of code
Expand Down Expand Up @@ -96,6 +100,13 @@ private fun IntentReceiver<SavedStateIntent>.SavedStateScreenContent(
) {
Text(Description.trimIndent())
Spacer(Modifier.height(24.dp))
if (BuildFlags.platform == Platform.Web) {
Text(
"You are on web, where persisting files to file system is not supported, " +
"so the data will not be saved",
color = MaterialTheme.colorScheme.error,
)
}
RTextInput(
input = input,
onTextChange = { intent(ChangedInput(it)) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package pro.respawn.flowmvi.sample.platform

interface FileManager {
fun cacheDir(relative: String): String
fun cacheDir(relative: String): String?
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package pro.respawn.flowmvi.sample.platform

import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem

internal class BrowserFileManager : FileManager {

override fun cacheDir(relative: String): String = SystemFileSystem.resolve(Path(relative)).name
override fun cacheDir(relative: String): String? = null
}

0 comments on commit dd8618f

Please sign in to comment.