Will a reaction be reactive even whithin a callback nested within the reaction? eg:
(r/reaction [:div {:on-click #(js/console.log @foo)}])No. The code inside that function literal isn't run during the reaction body execution, so deref isn't caught by reaction. Deref happens when the on-click callback is called.
I see, thank you.
so only ratoms that have been deref’ed once are reactive under reaction ? is it safe to assume that ?
Roughly so. The impl considers just the derefs from the previous reaction run.
If you have something like (when @a @b), b is watched for changes only when @a is truthly.
If a was falsey, b changes don't need to trigger reaction run. If b changes to truthly value AND then a changes to truthly, the reaction is run and reaction registers watch to both ratoms.
I see, thank you.
And if you want to know how this works. Reactions setup a dynamic binding to store the reaction context value and the deref method for reactive values (ratom, other reactions, cursor, track etc.) check for this dynamic binding and register themselves to that context. (Components etc. are just one type of "reaction".) There is not any code analyzing going on to find those derefs.