I am releasing my first Kotlin Multiplatform libra...
# feed
I am releasing my first Kotlin Multiplatform library. Support for android, ios, desktop, native and js. It's still under construction, 🚧👷🏾‍♂️🏗️ but SNAPSHOT builds are now out for feedback. API in the thread 🧵 https://github.com/xxfast/KStore
K 1
K 5
🎉 11
💯 2
Given that you have a
Copy code
@Serializable data class Pet(val name: String, val age: Int) // Any serializable
val mylo = Pet(name = "Mylo", age = 1)
Crate a store
Copy code
val store: KStore<Pet> = storeOf("path/to/file")
Get a value once
Copy code
val mylo: Pet? = store.get()
Observe for changes
Copy code
val pets: Flow<Pet?> = store.updates
Set value
Copy code
Update a value
Copy code
store.update { pet: Pet? ->
  pet?.copy(age = pet.age + 1)
Delete/Reset value
Copy code
store.delete() // sets to null
store.reset() // sets to default
Rest of the configurations
Copy code
private val store: KStore<Pet> = storeOf(
  path = filePathTo("file.json"), // required
  default = null, // optional
  enableCache = true, // optional
  serializer = Json, // optional