This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-26
Channels
- # adventofcode (12)
- # beginners (141)
- # cider (3)
- # cljsrn (3)
- # clojure (76)
- # clojure-russia (1)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (15)
- # css (1)
- # duct (3)
- # emacs (5)
- # fulcro (85)
- # keechma (1)
- # leiningen (44)
- # off-topic (29)
- # om (6)
- # parinfer (4)
- # perun (1)
- # re-frame (18)
- # reagent (2)
- # ring-swagger (8)
- # shadow-cljs (5)
- # spacemacs (1)
- # sql (7)
I've been using reagent.ratom/run!
to replace react life-cycle methods with simple FRP-ish computations. So for example:
(defn component
[]
(r/with-let [...
_ (r/run! (do-something @signals))]
[:div ...]))
Where (do-something @signals)
would otherwise need to be implemented across a number of life-cycle methods. I need these reactions to run right away, which is why I used run!
instead of reaction
.
However, I've noticed that, reactions created with run!
persist after a component has been unmounted, unliked those created by reaction
. This was unexpected. Looking at the source, it seems that any reaction with :auto-run
might never be disposed:
https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L355
I'm curious why that is? I supposed I can simply use @(reaction ...)
to get a disposable reaction that is run right away, but then what is the use case of run!
? Where might you use a reaction that will never be disposed?I realize now that @(reaction ...)
is insufficient, you need something more like:
(defn component
[]
(r/with-let [...
r (r/reaction (do-something @signals))]
@r
[:div ...]))
If you don't dereference r
with each render, the reaction will not be re-computed (hence the purpose of :auto-run
). Would be much more convenient if reactions with :auto-run
(i.e. run!
) could be disposed.