Fork me on GitHub
#reagent
<
2023-01-30
>
barrell10:01:10

I have a question with reagent atoms/cursors: I have a function I have to run a lot. I want to check a map ratom to see if the key exists, and if it does not exist, add it to the atom. Is there a 'fast' way to get the value of a ratom, without triggering any of the watchers etc? Alternatively I can create a cursor on the fly and dereference it, but I feel like that is probably more expensive. Anyways, I guess my question can be summed up: what is the fastest/most performant way to check if a ratom has a specific key?

p-himik11:01:30

"Get and update" should be expressed with swap!, which is a single operation. Even when there's no update. IIRC, changing a ratom's value multiple times within a single frame won't actually trigger any computations - it will simply mark the dependent reactions as dirty. The recomputations will be done once the reactions are queried, so at the end of the frame.

Sam Ritchie17:01:44

@U031G98S4GG I went through this with some animation code, the way is (.-state my-atom)