Skip to content

Commit

Permalink
save data to localstorage on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Apr 16, 2024
1 parent 2377b02 commit 61d6c10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ internal class SavedStateContainer(

// can also be injected, defined here for illustration purposes
// see "StoreConfiguration" for injection setup
// Saved state is not supported on wasm yet
fileManager.cacheDir("state")?.let {
serializeState(
dir = it,
json = json,
serializer = DisplayingInput.serializer(),
recover = NullRecover,
)
}
serializeState(
dir = fileManager.cacheDir(name!!),
json = json,
serializer = DisplayingInput.serializer(),
recover = NullRecover,
)

reduce { intent ->
when (intent) {
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
Expand Up @@ -2,5 +2,5 @@ package pro.respawn.flowmvi.sample.platform

internal class BrowserFileManager : FileManager {

override fun cacheDir(relative: String): String? = null
override fun cacheDir(relative: String): String = "cache/$relative"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package pro.respawn.flowmvi.savedstate.dsl

import kotlinx.browser.localStorage
import kotlinx.io.files.Path

internal actual suspend fun writeCompressed(data: String, to: Path) = write(data, to)
internal actual suspend fun writeCompressed(data: String, to: Path) = localStorage.setItem(to.name, data)

internal actual suspend fun readCompressed(from: Path): String? = read(from)
internal actual suspend fun readCompressed(from: Path): String? = localStorage.getItem(from.name)

0 comments on commit 61d6c10

Please sign in to comment.