Skip to content

Latest commit

 

History

History
373 lines (312 loc) · 10.5 KB

File metadata and controls

373 lines (312 loc) · 10.5 KB

Compose Extensions

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

All extensions functions are on StorageSetting<T> and following are available:

Available extensions are listed below:

StorageSetting.collectAsState(...) functions
@Composable
fun <T> StorageSetting<T>.collectAsState(
    initialValue: T? = getCachedValue()
): State<T?>
@Composable
fun <T, X> StorageSetting<T>.collectAsState(
    initialValue: T? = getCachedValue(),
    mapper: (T) -> X,
): State<X?>
StorageSetting.collectAsStateNotNull(...) functions
@Composable
fun <T> StorageSetting<T>.collectAsStateNotNull(
    initialValue: T = getValueNotNull()
): State<T>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateNotNull(
    initialValue: T = getValueNotNull(),
    mapper: (T) -> X,
): State<X>
StorageSetting.collectAsStateNotNull(...) functions
@Composable
fun <T> StorageSetting<T>.collectAsStateWithLifecycle(
    lifecycle: Lifecycle,
    initialValue: T? = tryGetValueNotNull(),
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext
): State<T?>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateWithLifecycle(
    lifecycle: Lifecycle,
    initialValue: T? = tryGetValueNotNull(),
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
): State<X?>
@Composable
fun <T> StorageSetting<T>.collectAsStateWithLifecycle(
    initialValue: T? = tryGetValueNotNull(),
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext
): State<T?>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateWithLifecycle(
    initialValue: T? = tryGetValueNotNull(),
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
): State<X?>
StorageSetting.collectAsStateWithLifecycleNotNull(...) functions
@Composable
fun <T> StorageSetting<T>.collectAsStateWithLifecycleNotNull(
    lifecycle: Lifecycle,
    initialValue: T = getValueNotNull(),
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
): State<T>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateWithLifecycleNotNull(
    lifecycle: Lifecycle,
    initialValue: T = getValueNotNull(),
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
): State<X>
@Composable
fun <T> StorageSetting<T>.collectAsStateWithLifecycleNotNull(
    initialValue: T = getValueNotNull(),
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext
): State<T>
@Composable
fun <T, X> StorageSetting<T>.collectAsStateWithLifecycleNotNull(
    initialValue: T = getValueNotNull(),
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
): State<X>
StorageSetting.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?>
StorageSetting.asMutableStateNotNull(...) functions
@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>
StorageSetting.asMutableStateWithLifecycle(...) functions
@Composable
fun <T> StorageSetting<T>.asMutableStateWithLifecycle(
    lifecycle: Lifecycle,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
): MutableState<T?>
@Composable
fun <T> StorageSetting<T>.asMutableStateWithLifecycle(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
): MutableState<T?>
@Composable
fun <T, X> StorageSetting<T>.asMutableStateWithLifecycle(
    lifecycle: Lifecycle,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
    unmapper: (X) -> T,
): MutableState<X?>
@Composable
fun <T, X> StorageSetting<T>.asMutableStateWithLifecycle(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
    unmapper: (X) -> T,
): MutableState<X?>
StorageSetting.asMutableStateWithLifecycleNotNull(...) functions
@Composable
fun <T> StorageSetting<T>.asMutableStateWithLifecycleNotNull(
    lifecycle: Lifecycle,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
): MutableState<T>
@Composable
fun <T> StorageSetting<T>.asMutableStateWithLifecycleNotNull(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
): MutableState<T>
@Composable
fun <T : Any, X : Any> StorageSetting<T>.asMutableStateWithLifecycleNotNull(
    lifecycle: Lifecycle,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
    unmapper: (X) -> T,
): MutableState<X>
@Composable
fun <T : Any, X : Any> StorageSetting<T>.asMutableStateWithLifecycleNotNull(
    lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    context: CoroutineContext = EmptyCoroutineContext,
    mapper: (T) -> X,
    unmapper: (X) -> T,
): MutableState<X>
StorageSetting.asStateFlow(...) functions
fun <T> StorageSetting<T>.asStateFlow(
    scope: CoroutineScope,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000)
): StateFlow<T?>
fun <T, T2> StorageSetting<T>.asStateFlow(
    scope: CoroutineScope,
    mapper: (T?) -> T2?,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
): StateFlow<T2?>
StorageSetting.asStateFlowNotNull(...) functions
fun <T> StorageSetting<T>.asStateFlowNotNull(
    scope: CoroutineScope,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000)
): StateFlow<T>
fun <T, T2> StorageSetting<T>.asStateFlowNotNull(
    scope: CoroutineScope,
    mapper: (T) -> T2,
    started: SharingStarted = SharingStarted.WhileSubscribed(5_000),
): StateFlow<T2>