reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
lsenjov 2021-02-09T03:02:37.053600Z

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}

lsenjov 2021-02-09T03:02:52.054Z

I expect the first deref to come up with the printlns, but I don’t expect it to the second time

lsenjov 2021-02-09T03:03:03.054300Z

Since the input atoms/reactions haven’t changed in the meantime

lsenjov 2021-02-09T03:04:01.055100Z

This is reagent 1.0.0

lsenjov 2021-02-09T03:04:39.055600Z

Is there a way to ensure things only update when the underlying atoms update?

lsenjov 2021-02-09T22:34:03.056100Z

Ah I see. I ended up using track! to make it reactive. Any issues with that off the top of your head?

p-himik 2021-02-10T06:53:43.056300Z

Sorry, no idea - I've never used it.

1👍
p-himik 2021-02-09T06:17:08.055700Z

This part of Reagent is not really documented, but reactions are reactive only when *ratom-context* is set. I.e. when rendering views.

1👍
lsenjov 2021-02-09T22:34:03.056100Z

Ah I see. I ended up using track! to make it reactive. Any issues with that off the top of your head?