Fork me on GitHub
#reagent
<
2018-11-29
>
credulous21:11:13

Hi, I’m having trouble correctly using track. I’d like to update my database when certain changes are made to my app state. Here’s a bit of test code I’m using.

credulous21:11:17

(def heat-sources (r/atom nil))

(defn source-count [] 
  (count @heat-sources))

(defn heat-sources-changed []
  (-> @(r/track source-count)
      (println "heat source chagned")))

credulous21:11:50

heat-sources gets set to an array of maps. The rest of the app is watching that atom and updating OK, so I know the atom is changing.

credulous21:11:02

But the println never gets called.

justinlee22:11:59

@credulous I think that track will only run if something is watching it. you might want something like the built-in add-watch. you could attach it to a cursor if you don’t want to restrict when it runs.

justinlee22:11:56

actually you might be able to use track!

credulous22:11:27

Thanks @lee.justin.m. track! does seem work, and I’ll look into add-watch