-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
177de83
commit 61aa042
Showing
7 changed files
with
30 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 24 additions & 24 deletions
48
composeApp/src/jsMain/kotlin/data/storage/LocalStorage.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
package data.storage | ||
|
||
import kotlinx.browser.window | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.w3c.dom.get | ||
import org.w3c.dom.set | ||
|
||
class WebLocalLocalStorage : LocalStorage { | ||
override suspend fun putString( | ||
key: String, | ||
value: String | ||
) = withContext(Dispatchers.Default) { | ||
window.localStorage[key] = value | ||
) { | ||
storage.setItem(key, value) | ||
} | ||
|
||
override suspend fun getString(key: String): String? = withContext(Dispatchers.Default) { | ||
window.localStorage[key] | ||
override suspend fun getString(key: String): String? { | ||
return storage.getItem(key) | ||
} | ||
|
||
override suspend fun putInt( | ||
key: String, | ||
value: Int | ||
) = withContext(Dispatchers.Default) { | ||
window.localStorage[key] = value.toString() | ||
) { | ||
storage.setItem(key, value.toString()) | ||
} | ||
|
||
override suspend fun getInt(key: String): Int? = withContext(Dispatchers.Default) { | ||
window.localStorage[key]?.toIntOrNull() | ||
override suspend fun getInt(key: String): Int? { | ||
return storage.getItem(key)?.toIntOrNull() | ||
} | ||
|
||
|
||
override suspend fun putDouble( | ||
key: String, | ||
value: Double | ||
) = withContext(Dispatchers.Default) { | ||
window.localStorage[key] = value.toString() | ||
) { | ||
storage.setItem(key, value.toString()) | ||
} | ||
|
||
override suspend fun getDouble(key: String): Double? = withContext(Dispatchers.Default) { | ||
window.localStorage[key]?.toDoubleOrNull() | ||
override suspend fun getDouble(key: String): Double? { | ||
return storage.getItem(key)?.toDoubleOrNull() | ||
} | ||
|
||
override suspend fun putBoolean( | ||
key: String, | ||
value: Boolean | ||
) = withContext(Dispatchers.Default) { | ||
window.localStorage[key] = value.toString() | ||
) { | ||
storage.setItem(key, value.toString()) | ||
} | ||
|
||
override suspend fun getBoolean(key: String): Boolean? = withContext(Dispatchers.Default) { | ||
window.localStorage[key]?.toBooleanStrictOrNull() | ||
override suspend fun getBoolean(key: String): Boolean? { | ||
return storage.getItem(key)?.toBooleanStrictOrNull() | ||
} | ||
|
||
override suspend fun remove(key: String) { | ||
window.localStorage.removeItem(key) | ||
storage.removeItem(key) | ||
} | ||
|
||
override suspend fun removeAll() { | ||
window.localStorage.clear() | ||
storage.clear() | ||
} | ||
|
||
override suspend fun keys(): List<String> { | ||
return (0..window.localStorage.length) | ||
return (0..storage.length) | ||
.mapNotNull { | ||
window.localStorage.key(it) | ||
storage.key(it) | ||
} | ||
} | ||
|
||
private val storage | ||
get() = window.localStorage | ||
} | ||
|
||
actual fun localStorage(): LocalStorage = WebLocalLocalStorage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters