In the Android samples/examples of Workflow (<http...
# squarelibraries
b
In the Android samples/examples of Workflow (https://github.com/square/workflow-kotlin), at each
showRendering
click listeners are set (as below).
Copy code
override fun showRendering(rendering: Rendering) {
      messageView.setOnClickListener { rendering.onClick(Unit) }
}
This means it will be set (unnecessarily) at every
Rendering
state change. I don't imagine click listeners to be dynamic very often. What is the reasoning?
r
They may well change on each rendering (and in earlier versions of the library did). It is none of the view’s business whether that is true or not. And anyway, any mechanism to allow the view to decide whether or not to update that pointer is going to be more complex and costly than simply setting it.
👍 1
Similar reasoning for lack of debouncing of redundant update calls to views in general: a view is in the best position to decide whether it’s already showing value “Foo”, and whether it should invalidate itself or not.
b
Gotcha. Thanks.
z
This pattern also exists in Compose, FYI. When you pass a callback to a composable, you often just do it inline. If your function gets re-invoked, it will pass the lambda again.
👍 1
b
I haven't played around with Compose yet. Will check it out some day soon. Thanks @Zach Klippenstein (he/him) [MOD]