Fork me on GitHub
#re-frame
<
2015-11-07
>
richiardiandrea01:11:08

Hello guys... in order to negate a subscription, do I need to create another subscription or deref subscribe and then negate the result?

mikethompson01:11:54

negate a subscription?

richiardiandrea01:11:08

I mean if I have (subscribe [:console-created? :cljs-console]) and what I need to return is actually the negation..do I have to (not @(subscribe [:console-created? :cljs-console])) ?

richiardiandrea01:11:00

i would like to share code in the register-sub

richiardiandrea02:11:17

yes it works with the trick above, you first deref the result of subscribe and then apply not

mikethompson02:11:20

Be careful ... that not won't "rerun" when the subscription gets a new value unless you ....

(let  [val       (subscribe [:console-created? :cljs-console])
       not-val   (reaction  (not @val))]       ;;  <--    if val changes, also make not-val change
   ...
Or just use (not @val) in the body of the renderer

mikethompson02:11:08

But definitely do NOT do this:

(let  [val       (not @ (subscribe [:console-created? :cljs-console]))]
   ...

richiardiandrea04:11:12

yes it is directly in a re-com :disabled? property, therefore should be inside a component