KStore

class KStore<T : @Serializable Any>(default: T? = null, enableCache: Boolean = true, codec: Codec<T>)

Creates a store with a custom encoder and a decoder

Parameters

default

returns this value if the decoder returns null. defaults to null

enableCache

maintain a cache. If set to false, it always reads from decoder

codec

codec to use to encode/decode a value with/from

Constructors

Link copied to clipboard
constructor(default: T? = null, enableCache: Boolean = true, codec: Codec<T>)

Properties

Link copied to clipboard
val <T : @Serializable Any> KStore<T>.cached: T?

Get the cached value synchronously. Note: This value will be set even when the store's KStore.enableCache is set to false. Note: This value can be null if

Link copied to clipboard
val updates: Flow<T?>

Observe store for updates

Link copied to clipboard
val <T : @Serializable Any> KStore<List<T>>.updatesOrEmpty: Flow<List<T>>

Observe a list store for updates

Functions

Link copied to clipboard
suspend fun delete()

Set the value of the store to null

Link copied to clipboard
suspend fun get(): T?

Get a value from the store

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.get(index: Int): T?

Get an item from list of type T from the store, or null if the store is empty

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.getOrEmpty(): List<T>

Get a list of type T from the store, or empty list if the store is empty

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.map(operation: (T) -> T)

Updates the list by applying the given operation lambda to each element in the stored list.

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.mapIndexed(operation: (Int, T) -> T)

Updates the list by applying the given operation lambda to each element in the stored list and its index in the stored collection.

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.minus(vararg value: T)

Remove item(s) of type T from the list in the store

Link copied to clipboard
suspend fun <T : @Serializable Any> KStore<List<T>>.plus(vararg value: T)

Add item(s) to the end of the list of type T to the store

Link copied to clipboard
suspend fun reset()

Set the value of the store to the default

Link copied to clipboard
suspend fun set(value: T?)

Set a value to the store

Link copied to clipboard
suspend fun update(operation: (T?) -> T?)

Update a value in a store. Note: This maintains a single mutex lock for both get and set