Is `derivedStateOf` considered “changed” when any ...
# compose
o
Is
derivedStateOf
considered “changed” when any of its tracked states change, even if yielded value is the same?
s
Yes, it is up to observer to compare the values and continue the update. We've recently added a mutation policy to change this a little for e.g. derived states used in other derived states The important part is that changing any of the tracked states read in derived state is usually invalidating composition, it just decides to skip if derived state value didn't change
o
My case is not about composition, actually, but about
drawWithCache
. Sorry for not mentioning it. I have pretty complex drawing (kinda map) with zooming, panning, hovering, clicking – all these sorts of things. So there is a long chain of derived states, mostly starting from mouse position, like hoveredArea but they rarely actually change the value. E.g. if mouse is moving inside the same hovered area nothing changes that is being read in the draw code, but redraws happen.
s
Interesting, drawing should also be covered by the comparisons in SnapshotStateObserver
You can try applying mutation policy to derived states within the chain so they are not forcing downstream updates
o
How do I apply that policy?
s
First parameter of derivedStateOf overload
o
I’m on desktop compose 1.2.0-alpha01-dev774, so probably it didn’t get there yet… I don’t have any overloads on derivedStateOf
s
Ah, that explains it It was added back in July, together with proper support for derived states in draw/measure
o
cc @Igor Demin
i
If it was added in July, then most probably it will be only in Jetpack Compose 1.3.0-alphaXX. Compose Multiplatform will be rebased on it after we release Compose MPP 1.2.0
o
No hurry, I have enough performance for now :) Just wanted to make sure I'm not missing something in my code
Now that you’re done, any ETA on rebase?
i
1-3 weeks