From cd73791b6fcbb7f8271b971fe54f1bc7e23dbf39 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 29 Jan 2023 12:46:27 +0600 Subject: [PATCH] add docs to the MutableState.asState --- CHANGELOG.md | 2 ++ .../inmo/micro_utils/common/compose/MutableStateAsState.kt | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98da26f5385..2736ba38b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Diff` now is serializable * Add `IndexedValue` serializer * `repeatOnFailure` extending: now you may pass any lambda to check if continue to try/do something + * `Compose`: + * New extension `MutableState.asState` * `Coroutines`: * `Compose`: * `asMutableComposeState` and all depending functions now use `doInUI` to guarantee state changin in Main Dispatcher diff --git a/common/compose/src/commonMain/kotlin/dev/inmo/micro_utils/common/compose/MutableStateAsState.kt b/common/compose/src/commonMain/kotlin/dev/inmo/micro_utils/common/compose/MutableStateAsState.kt index b551a9e6b74..11be8cd5669 100644 --- a/common/compose/src/commonMain/kotlin/dev/inmo/micro_utils/common/compose/MutableStateAsState.kt +++ b/common/compose/src/commonMain/kotlin/dev/inmo/micro_utils/common/compose/MutableStateAsState.kt @@ -1,6 +1,10 @@ package dev.inmo.micro_utils.common.compose import androidx.compose.runtime.MutableState +import androidx.compose.runtime.State import androidx.compose.runtime.derivedStateOf -fun MutableState.asState() = derivedStateOf { this.value } +/** + * Converts current [MutableState] to immutable [State] using [derivedStateOf] + */ +fun MutableState.asState(): State = derivedStateOf { this.value }