add extension toMutableListState

This commit is contained in:
InsanusMokrassar 2022-06-22 16:09:52 +06:00
parent d8f01f21a0
commit 86e74c0a6f
2 changed files with 23 additions and 0 deletions

View File

@ -2,6 +2,8 @@
## 0.11.4
* Add extension `StateFlow#toMutableListState`
## 0.11.3
* `Ktor`:

View File

@ -0,0 +1,21 @@
package dev.inmo.micro_utils.coroutines.compose
import androidx.compose.runtime.*
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 <reified T> StateFlow<List<T>>.toMutableListState(
scope: CoroutineScope
): SnapshotStateList<T> {
val state = mutableStateListOf(*value.toTypedArray())
subscribeSafelyWithoutExceptions(scope) {
state.applyDiff(it)
}
return state
}