From b1e3dcc3237f0bf36202e001b1840de5d71da621 Mon Sep 17 00:00:00 2001 From: Veyndan Stuart Date: Thu, 28 Sep 2023 11:40:11 +0200 Subject: [PATCH] When deserializing a `MutableState`, also deserialize its value --- .../kotlin/app/cash/redwood/treehouse/StateSnapshot.kt | 2 +- .../kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/StateSnapshot.kt b/redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/StateSnapshot.kt index fb69964e9b..6faaefed49 100644 --- a/redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/StateSnapshot.kt +++ b/redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/StateSnapshot.kt @@ -34,7 +34,7 @@ public class StateSnapshot( return content.mapValues { entry -> entry.value.map { if (it.isMutableState) { - mutableStateOf(it.value) + mutableStateOf(it.value.fromJsonElement()) } else { it.value.fromJsonElement() } diff --git a/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt b/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt index c25c93f534..8d1bfc3987 100644 --- a/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt +++ b/redwood-treehouse/src/commonTest/kotlin/app/cash/redwood/treehouse/StateSnapshotTest.kt @@ -32,12 +32,12 @@ class StateSnapshotTest { val valuesMap = stateSnapshot.toValuesMap() assertThat(valuesMap.entries.size).isEqualTo(4) assertTrue(valuesMap["key1"]!![0] is MutableState<*>) - assertThat((valuesMap["key1"]!![0] as MutableState<*>).value).isEqualTo(JsonPrimitive(1)) + assertThat((valuesMap["key1"]!![0] as MutableState<*>).value).isEqualTo(1.0) assertThat(valuesMap["key2"]).isEqualTo(listOf(1.0)) assertThat(valuesMap["key3"]!![0] is MutableState<*>) - assertThat((valuesMap["key3"]!![0] as MutableState<*>).value).isEqualTo(JsonPrimitive("str")) + assertThat((valuesMap["key3"]!![0] as MutableState<*>).value).isEqualTo("str") assertThat(valuesMap["key4"]).isEqualTo(listOf("str")) }