I’m having what I believe is a major misunderstanding of reactions. As far as I know, reactions should only be updating when the reactions/atoms they rely on update, but this doesn’t appear to be the case
(def a0 (r/atom {:a 0}))
(def a1 (ratom/reaction (println "proc: a1") (update @a0 :a inc)))
(def a2 (ratom/reaction (println "proc: a2") (update @a1 :a inc)))
(def a3 (ratom/reaction (println "proc: a3") (update @a2 :a inc)))
=> #'user/a0
=> #'user/a1
=> #'user/a2
=> #'user/a3
@a3
proc: a3
proc: a2
proc: a1
=> {:a 3}
@a3
proc: a3
proc: a2
proc: a1
=> {:a 3}
I expect the first deref to come up with the printlns, but I don’t expect it to the second time
Since the input atoms/reactions haven’t changed in the meantime
This is reagent 1.0.0
Is there a way to ensure things only update when the underlying atoms update?
Ah I see. I ended up using track!
to make it reactive. Any issues with that off the top of your head?
Sorry, no idea - I've never used it.
This part of Reagent is not really documented, but reactions are reactive only when *ratom-context*
is set. I.e. when rendering views.