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
1 changed files with 5 additions and 9 deletions

View File

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