From eae30c738acd1a6bf573d6b782b57169eb716208 Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Mon, 8 Jan 2024 11:25:28 +0200 Subject: [PATCH] fix(ViewModel): Use single source of compose state --- .../navigation/state/RememberStateFlowScopeImpl.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScopeImpl.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScopeImpl.kt index 96009f7..f0e1f23 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScopeImpl.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/navigation/state/RememberStateFlowScopeImpl.kt @@ -263,15 +263,11 @@ class RememberStateFlowScopeImpl( } override fun mutableComposeState(sink: MutableStateFlow): MutableState { - 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 } override fun persistedState(): LeBundle {