Is there a way to always trigger recomposition by ...
# compose
r
Is there a way to always trigger recomposition by setting a
MutableState
variable, including when the contents are the same? I've Tried creating my own
SnapshotMutationPolicy
but the
merge
method never gets called.
a
Override the
equals()
function and return false I guess
t
This is a code smell. What are you really trying to do?
a
r
I've done that already @André Kindwall. Here is a full implementation of my
SnapshotMutationPolicy
Copy code
private object AlwaysApplyPolicy : SnapshotMutationPolicy<String> {

    override fun equivalent(a: String, b: String): Boolean = false

    override fun merge(previous: String, current: String, applied: String): String? {
        return current
    }

    override fun toString() = "AlwaysApplyPolicy"
}
What I want is for the
State
backed by this snapshot policy to always force a recomposition when it's value get's set, even if the previous value is equal to the current value.
a
You should probably ask a new question where you describe what you want to achieve, not how you think you can achieve it (the xy problem). It sounds to me like you are trying to trigger some event, if that is the case then that should be handled by collecting a flow inside a sideeffect
t
Why do you want to recompose with the same value?