Fork me on GitHub

I’ve got a map representing some exhaust gas whose parameters are modified on a webpage. I’d like to call back to the server to do a calculation on that every time the structure is modified. I’m trying reagent.core/track, but I don’t think I’m using it right.


fluegas is a reagent atom - (def fluegas (r/atom {:mol_fraction? true :t0 350 :pressure 101325 :flow 50 :t1 140 :mix { :Water 0.20 :CO2 0.08 :O2 0.022 :N2 0.698}}))


Then in the same file I try to use reagent.core/track:


(defn calculate-thermal-availability [heatsource]
   (ajax/POST "/app/thermal_availability" :params @heatsource :format :json
              :handler (fn [response] (println response)
                         (reset! thermal-availability (:availability response)))))
 (r/track calculate-thermal-availability fluegas)


But calculate-thermal-availability doesn’t get called when I modify the fluegas atom. I’m clearly misunderstanding r/track, any pointers?


(thermal-availability is also a reagent atom)


Question for the channel: Has anyone migrated an existing JavaScript app to ClojureScript piecemeal? We have such an app that we would like to migrate from JS (uses React) to ClojureScript but do not have the time to do a wholesale re-write. My first inclination was to attempt to wrap the existing application in a Reagent application. If that was possible (has anyone done that? is that a good idea?) it would put us in a nice place as we could do all new dev in ClojureScript and then move existing JS functionality over to CLJS as needed or when time permitted. Any thoughts/tutorials/suggestions would be greatly appreciated. Thanks!


As far as thoughts you could make small sections of it in reagent and mount those small sections individually. Instead of having one large mounted app that controls everything you could make a couple of small apps and slowly build up to having the full app in reagent


do like

(do (reagent/render [sidebar] (.getElementById js/document "sidebar"))
    (reagent/render [header] (.getElementById js/document "header")))


I see. The mounted sections could invoke the relevant existing JS code (or newly created CLJS) and over time the JS bits could be migrated to CLJS.


I'm trying to apply the withAlert decorator, this is my chain of calls from a function

then I call that function with hiccup, but I'm getting errors I bet someone here can see quickly where I'm off track?


ah got it

(defn x []
and call it
[:> (x)]
strange but it works.


anyway, I encourage looking at how reagent interops with a library like this it seems that both ways of using it, callback as child, and decorator passing props. Doesn't fit well. Objects aren't valid children and my (probably wrong) way of using decorator wont re-render after props change (value stay undefined but the passed on key is present).


if interop with libraries like this is important to you, I would encourage you to check out a library I’ve been working on:


it’s still a WIP but is pretty functional. it’s aim is to ease a lot of these issues I encountered doing raw React interop in reagent


hmm nice, I grab to pure reagent for small projects. I will bookmark this library for future, seems like easy jump from reagent.


but in the end I didn't use this react-alert, found something that looks and works better.