reagent

Quentin Le Guennec 2024-11-12T08:08:01.259329Z

Will a reaction be reactive even whithin a callback nested within the reaction? eg:

(r/reaction [:div {:on-click #(js/console.log @foo)}])

juhoteperi 2024-11-12T08:18:01.568889Z

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.

Quentin Le Guennec 2024-11-12T08:35:36.718649Z

I see, thank you.

Quentin Le Guennec 2024-11-12T08:37:16.724509Z

so only ratoms that have been deref’ed once are reactive under reaction ? is it safe to assume that ?

juhoteperi 2024-11-12T18:39:42.422609Z

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.

Quentin Le Guennec 2024-11-13T09:03:16.939389Z

I see, thank you.

juhoteperi 2024-11-13T09:06:36.267929Z

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.