@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.
@sansaripour Making sure you see this to avoid repeating the whole message in #re-frame
@p-himik 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.
Same reason why you cannot use subscribe
in a re-frame or a JS event handler.
is that still true when using a form-1 and binding w/o derefing it in the let
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.
cool, checking my understand
thanks for the explanation, it’s more clear now
wow
good to know