Try using reagent.ratom/run! macro. It subscribes to all the dereferenced reaction/ratoms/etc inside its body and executes the body on changes:
(ns foo.bar (:require [reagent.core :as r]) (:require-macros [reagent.ratom :refer [reaction run!]])) (run! (println "Result updated:" @tracked-result)) On Thursday, August 3, 2017 at 3:45:55 AM UTC+3, john...@gmail.com wrote: > > Hi, > > I'm using reagent/track on a function that references several ratoms and > calculates a value. I need to integrate with a JavaScript library and call > a function when the tracked value changes. I tried using add-watch on the > tracked value, but I get the following error: > > Error: No protocol method IWatchable.-add-watch defined for type > reagent.ratom/Track > > My code looks something like this: > > (defn calculate-value [] > ; references several ratoms to calculate result) > > (def tracked-result (reagent/track calculate-value)) > > (defn result-changed [_key _reference old-value new-value] > ; call library function) > > (add-watch tracked-result ::refresh result-changed) > > I thought about calling add-watch on each individual ratom referenced by > calculate-value, but that seems repetitive. Any ideas on another way to > solve this problem? Essentially, I need a way to be notified when the > tracked value changes. Thanks! > -- You received this message because you are subscribed to the Google Groups "Reagent-Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to reagent-project+unsubscr...@googlegroups.com. To post to this group, send email to reagent-project@googlegroups.com. Visit this group at https://groups.google.com/group/reagent-project. For more options, visit https://groups.google.com/d/optout.