Fork me on GitHub
#re-frame
<
2017-06-09
>
borkdude17:06:58

What is a good way to execute some function whenever a subscription changes to a certain value?

borkdude17:06:27

I don’t need the value in a component

borkdude17:06:25

A Reagent reaction?

pesterhazy17:06:16

the other way would be to create a Form-3 component which dereferences the subscription, with a component-did-update lifecycle method. I think a component's did-update will fire when a watched atom changes.

pesterhazy17:06:59

a thing to be aware of is that adding side effects to state changes is frowned upon by some

borkdude17:06:53

I know, but this is an experiment

borkdude17:06:00

with iframes communicating

borkdude17:06:15

I’ll clean it up once it works 😉

pesterhazy17:06:25

I see, good point

pesterhazy17:06:36

The rules of the game for experiments are different

pesterhazy17:06:58

r/track! is your friend then, it works nicely

borkdude17:06:25

yes, it works, thanks!

pesterhazy17:06:28

I guess you'll still need to create the track! inside a lifecycle method

pesterhazy17:06:50

you're welcome 🙂

borkdude17:06:07

This worked:

(defn foo []
  (let [done? @(subscribe [::subs/widgets-done?])]
    (when done? (js/alert “done!“))))

(r/track! foo)

pesterhazy17:06:32

heh, yeah running it as a top level form would work too 🙂