This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-13
Channels
- # announcements (5)
- # babashka (35)
- # beginners (65)
- # braveandtrue (3)
- # calva (20)
- # cider (6)
- # clara (11)
- # cljs-dev (36)
- # cljsrn (64)
- # clojure (65)
- # clojure-europe (6)
- # clojure-germany (13)
- # clojure-italy (14)
- # clojure-nl (22)
- # clojure-spec (16)
- # clojure-sweden (6)
- # clojure-uk (81)
- # clojurescript (71)
- # conjure (120)
- # cursive (3)
- # datomic (10)
- # events (4)
- # figwheel (4)
- # figwheel-main (5)
- # fulcro (36)
- # ghostwheel (1)
- # graalvm (8)
- # helix (9)
- # jobs (4)
- # jobs-discuss (12)
- # kaocha (33)
- # leiningen (5)
- # luminus (1)
- # off-topic (24)
- # pathom (7)
- # rdf (4)
- # re-frame (3)
- # reagent (15)
- # reitit (11)
- # remote-jobs (1)
- # shadow-cljs (97)
- # slack-help (3)
- # spacemacs (23)
- # vim (15)
- # xtdb (35)
@wvelezva @lilactown It's not just a matter o f taste. Notice the component has if
in there. If you use a form-2 component where some subs are @
-ed only in one of the branches, then you will have memory leaks.
@UJ3SAFCQL Making sure you see this to avoid repeating the whole message in #re-frame
@U2FRKM4TW thanks for you answer, final question, what do you recommend in this case?
I just use @(subscribe [...])
everywhere. The only reason to not use @
right away is if you want to interact with the ratom itself.
Check this out, along with the next section: https://github.com/day8/re-frame/blob/master/docs/SubscriptionsCleanup.md#another-technique
I also use @(subscribe [...])
everywhere, I just wanted to know if the other way has strong advantages
hm. I’m not sure why you would have a memory leak problem doing:
(defn c []
(let [x (rf/subscribe [:x])
y (rf/subscribe [:y])]
(fn []
[:div (if @x @y "no y")])))
vs not wrapping in a fn
If you do not deref a ratom, on-dispose
will never be called when the view is unmounted.
If you never @
a sub, then it is true.
But it's OK with (if @(subscribe [...]) @(subscribe [...]) "no y")
because the second subscribe
will not be called unless the first one returns true.
thanks for the explanation, it’s more clear now
good to know