From 9cf01ab54fd9d91bebee8455b07e07de7970ee21 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:56:51 +0600 Subject: [PATCH] improve compose list state creation --- .../inmo/micro_utils/coroutines/compose/FlowAsListState.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt index 6004f9d918f..3ce3e860eac 100644 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt @@ -5,13 +5,14 @@ import androidx.compose.runtime.snapshots.SnapshotStateList import dev.inmo.micro_utils.common.applyDiff import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @Suppress("NOTHING_TO_INLINE") -inline fun StateFlow>.asMutableComposeListState( +inline fun Flow>.asMutableComposeListState( scope: CoroutineScope ): SnapshotStateList { - val state = mutableStateListOf(*value.toTypedArray()) + val state = mutableStateListOf() subscribeSafelyWithoutExceptions(scope) { state.applyDiff(it) } @@ -19,7 +20,7 @@ inline fun StateFlow>.asMutableComposeListState( } @Suppress("NOTHING_TO_INLINE") -inline fun StateFlow>.asComposeList( +inline fun Flow>.asComposeList( scope: CoroutineScope ): List = asMutableComposeListState(scope)