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 = getValueNotNull(),
    mapper: (T) -> X,
): State<X>

asMutableState* functions#

@Composable
fun <T> StorageSetting<T>.asMutableState(): MutableState<T?>
@Composable
fun <T, X> StorageSetting<T>.asMutableState(
    mapper: (T) -> X,
    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#

fun <T> StorageSetting<T>.asStateFlow(
    scope: CoroutineScope,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
    apply: (flow: Flow<T>) -> Flow<T> = { it }
): StateFlow<T?>
fun <T> StorageSetting<T>.asStateFlow(
    scope: CoroutineScope,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
    apply: (flow: Flow<T>) -> Flow<T> = { it }
): StateFlow<T?>
fun <T> StorageSetting<T>.asStateFlowNotNull(
    scope: CoroutineScope,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
    apply: (flow: Flow<T>) -> Flow<T> = { it }
): StateFlow<T>
fun <T, T2> StorageSetting<T>.asStateFlowNotNull(
    scope: CoroutineScope,
    mapper: (T) -> T2,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
): StateFlow<T2>