fix(ViewModel): Use single source of compose state

This commit is contained in:
Artem Chepurnoy 2024-01-08 11:25:28 +02:00
parent 40bea14162
commit eae30c738a
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E

View File

@ -263,15 +263,11 @@ class RememberStateFlowScopeImpl(
} }
override fun <T> mutableComposeState(sink: MutableStateFlow<T>): MutableState<T> { override fun <T> mutableComposeState(sink: MutableStateFlow<T>): MutableState<T> {
val state = mutableStateOf(sink.value) val entry = registry.values.firstOrNull { it.sink === sink }
// Send back the data from a source of truth to the requireNotNull(entry) {
// screen's storage. "Provided sink must be created using mutablePersistedFlow(...)!"
snapshotFlow { state.value }
.onEach { text ->
sink.value = text
} }
.launchIn(screenScope) return entry.composeState.mutableState as MutableState<T>
return state
} }
override fun persistedState(): LeBundle { override fun persistedState(): LeBundle {