Raid Xu
06/14/2022, 5:07 PMstate: State<T>
in it, then dispose the snapshot, the created state
can’t be read from GlobalSnapshot
, which makes sense.
However if anything triggered advanceGlobalSnapshot
(for example registerApplyObserver
), the new GlobalSnaphot
will be able to read the state
now (because the new GlobalSnapshot
no longer remember the disposed snapshot in invalid snapshots). Is this a bug?Raid Xu
06/15/2022, 5:57 AM@Test
fun `test state created in inner snapshot can be read from outer snapshot`() {
var stateCreatedInSnapshot: MutableState<Int>? = null
Snapshot.takeSnapshot().run {
try {
enter { stateCreatedInSnapshot = mutableStateOf(0) }
} finally {
dispose()
}
}
// Snapshot.registerApplyObserver { _, _ -> } // with this line the following line will NOT explode
println("stateCreatedInSnapshot=${stateCreatedInSnapshot?.value}")
}
Saiedmomen
06/15/2022, 6:01 AMSaiedmomen
06/15/2022, 6:03 AMRaid Xu
06/15/2022, 6:07 AMadvanceGlobalSnapshot
shouldn’t automatically commit any snapshots. (I could be wrong since I’m new to snapshots)Saiedmomen
06/15/2022, 6:17 AMRaid Xu
06/16/2022, 8:04 AMZach Klippenstein (he/him) [MOD]
06/18/2022, 1:35 AMChuck Jazdzewski [G]
06/18/2022, 1:39 AMRaid Xu
06/18/2022, 6:44 AMadvanceGlobalSnapshot
?