Closed qbait closed 5 years ago
@qbait when you do
onClick { _ -> state.doSomething }
, you are implicitly capturing the state inside the lambda, and since state
is a data class, it's making a copy. When epoxy rebuild the model, callbacks are not hashed, so it still has the old lambda capturing the old state
.
Here's 2 solutions you can consider
state
to showConfirmation
. call withState
inside showConfirmation
to get the most up to date stateclass KeyedOnClickListener {
val key: WhateverKeyThatHasAProperlyDefinedHashFunction
val listener: OnClickListener
func hashCode() {
return key.hashCode
}
}
^^ (pseudocode above)
Not sure if option 2 is already supported in epoxy? @elihart @BenSchwab @gpeal
I have my button declared like that
For some reason, my state in
onClick
isn't refreshed until I will scroll myRecyclerView
. The state in the button is always up to date.Do you have an idea of what could be an issue or shall I prepare a simplified sample project?
[EDIT] I solved it by adding
val showConfirmation: Boolean
to my state. My epoxy config looks now like thatLet me know if it's a good practice what I did and I'm still curious why onClick has outdated state.