mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-19 23:03:49 +00:00
add extension toMutableListState
This commit is contained in:
parent
d8f01f21a0
commit
86e74c0a6f
@ -2,6 +2,8 @@
|
||||
|
||||
## 0.11.4
|
||||
|
||||
* Add extension `StateFlow#toMutableListState`
|
||||
|
||||
## 0.11.3
|
||||
|
||||
* `Ktor`:
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user