Skip to content

Compose

This module is placed inside the extension-compose artifact and offers some helpful compose extensions for the Storage class.

collectAsState* functions#

@Composable
fun <T> StorageSetting<T>.collectAsState(
    initialValue: T? = getCachedValue(),
    apply: (flow: Flow<T>) -> Flow<T> = { it }
): State<T?>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateMapped(
    initialValue: T? = getCachedValue(),
    mapper: (T) -> X,
): State<X?>

collectAsStateNotNull#

@Composable
fun <T> StorageSetting<T>.collectAsStateNotNull(
    initialValue: T = getValueNotNull(),
    apply: (flow: Flow<T>) -> Flow<T> = { it }
): State<T>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateMappedNotNull(
    initialValue: T = getCachedValue() ?: getValueNotNull(),
    mapper: (T) -> X,
): State<X>

asMutableState* functions#

@Composable
inline fun <reified T> StorageSetting<T>.asMutableState(): MutableState<T?>
@Composable
inline fun <reified T, reified X> StorageSetting<T>.asMutableState(
    crossinline mapper: (T) -> X,
    crossinline unmapper: (X) -> T,
): MutableState<X?>
@Composable
fun <T> StorageSetting<T>.asMutableStateNotNull(): MutableState<T>
@Composable
fun <T : Any, X : Any> StorageSetting<T>.asMutableStateNotNull(
    mapper: (T) -> X,
    unmapper: (X) -> T,
): MutableState<X>

asStateFlow* functions#