Fork me on GitHub
#reagent
<
2022-10-27
>
Sam Ritchie13:10:44

is there a way to force all, or some set, of a component’s children to re-render when ANY of the children are updated? I know this isn’t quite “idiomatic”… but the mutable object that I am reactifying, the Board, has a 1-layer-deep set of children, and adds them all in order. later children in the list can depend on earlier children (`Angle` is defined by supplying the IDs of three Points that have already been added for example); so if any of the points change, I want to remove and re-add everything that came after that Point. Or, simpler, just re-render the entire child set when the properties of any children change. is there some way to trigger that? the best way I can imagine is to • make a ratom with a :forceUpdate key • pass it to all children • any time a child updates, it can (swap! !state update :forceUpdate inc)

Lone Ranger14:10:16

hi it's me again! This is probably not what you want ultimately but you can at least prototype to see if it works with reagent.dom/force-update-all! https://reagent-project.github.io/docs/master/reagent.dom.html But being free from idiomatic conventions can be so darn liberating 😁 and we've already left kansas so why not

👍 1
Sam Ritchie14:10:40

I bet that will work, but I will say that it would be nice to have it only apply to all the children, or even better all the children including and AFTER the one that is updated

Sam Ritchie14:10:09

The former I can do, the latter probably is not necessary as an optimization…

Sam Ritchie14:10:54

But that is great advice, if rerender all doesn’t work then I’ll know there is something else fishy with mutability that would have been harder to discover without this

Sam Ritchie14:10:28

I realized that with the amount of mutable state going on under the hood, I really can’t be clever at all here, and need to re-render ALL children any time anything changes for any of them. this makes the code simpler… instead of forceupdate and friends, I • keep a ratom with a counter, • increment the counter every time render is called on the JSXGraph top level component • pass the mutable board instance and the counter value along as a prop to every child then each child adds itself to the board every time component-did-update is called.

Sam Ritchie14:10:02

not perfect but until the underlying library is more amenable, this is pretty good!