suika
09/03/2025, 7:33 AM@Test
fun myTest() {
fun myPolicy(): SnapshotMutationPolicy<Int> = object : SnapshotMutationPolicy<Int> {
override fun equivalent(a: Int, b: Int): Boolean {
println("equivalent a: $a, equivalent b: $b")
return a == b
}
override fun merge(previous: Int, current: Int, applied: Int): Int {
println("previous: $previous, current: $current, applied: $applied")
return applied
}
}
val state = mutableStateOf(0, myPolicy())
val snapshot1 = Snapshot.takeMutableSnapshot()
val snapshot2 = Snapshot.takeMutableSnapshot()
val snapshot3 = Snapshot.takeMutableSnapshot()
val snapshot4 = Snapshot.takeMutableSnapshot()
snapshot1.enter {
state.value = 10
}
snapshot2.enter {
state.value = 20
}
snapshot3.enter {
state.value = 30
}
snapshot4.enter {
state.value = 40
}
snapshot1.apply() // previous: 40, current: 0, applied: 10
snapshot2.apply() // previous: 40, current: 10, applied: 20
snapshot3.apply() // previous: 0, current: 20, applied: 30
snapshot4.apply() // previous: 0, current: 30, applied: 40
}
Zach Klippenstein (he/him) [MOD]
09/03/2025, 3:36 PMChuck Jazdzewski [G]
09/03/2025, 5:50 PMsuika
09/03/2025, 6:12 PMZach Klippenstein (he/him) [MOD]
09/03/2025, 6:13 PMChuck Jazdzewski [G]
09/04/2025, 3:50 PM