mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
potential fix of state value change in asMutableComposeState
This commit is contained in:
parent
8a6b4bb49e
commit
6ebc5aa0c2
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.coroutines.compose
|
package dev.inmo.micro_utils.coroutines.compose
|
||||||
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import dev.inmo.micro_utils.coroutines.doInUI
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@ -11,7 +12,7 @@ fun <T> Flow<T>.asMutableComposeState(
|
|||||||
scope: CoroutineScope
|
scope: CoroutineScope
|
||||||
): MutableState<T> {
|
): MutableState<T> {
|
||||||
val state = mutableStateOf(initial)
|
val state = mutableStateOf(initial)
|
||||||
subscribeSafelyWithoutExceptions(scope) { state.value = it }
|
subscribeSafelyWithoutExceptions(scope) { doInUI { state.value = it } }
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user