The 'previous' in Snapshot is difficult to underst...
# compose
s
The 'previous' in Snapshot is difficult to understand. Why is 'previous' either 40 or 0?
Copy code
@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
}
z
I would also expect previous to be 0 for all of them. Cc @Chuck Jazdzewski [G]
c
This looks like a bug in how I calculate the previous value. Can you submit this as a bug with the above as the steps?
s
@Zach Klippenstein (he/him) [MOD] @Chuck Jazdzewski [G] Thanks, I submitted the issue: https://issuetracker.google.com/issues/442791065
z
you don't need to tag folks who've responded in a thread, they get notified of replies automatically
👍 1
c
I am impressed that you resisted the temptation to at suika in the that response 🙂