Fork me on GitHub
Charles Comstock22:03:55

I'm trying to make a persistent animated canvas component that only rescales it's context to the appropriate DPI if the size changes, and the logic for scaling is buried inside of a requestAnimationFrame. Unfortunately I'm having difficulty using r/track inside of the animation loop to only trigger side-effects like updating the context if the atom containing the canvas dimensions is changed. The behavior I'm seeing is that it always executes on every frame, instead of returning the memoized value and updating on change. I've had this working before in another context, but my suspicion is it was because the r/track calls were happening inside of rendering functions directly. I'm curious if anyone has explored this problem and has any insights into it, or at least can point to better resources explaining the conditions under which r/track is lazy.


The caching works properly only within reactive contexts - when reagent.ratom/reactive? returns true. Which is for views and other reactions used in views.

Charles Comstock22:03:10

Gotcha, thats a useful flag to be able to check, thanks