Fork me on GitHub
#reagent
<
2018-11-06
>
credulous15:11:42

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.

credulous15:11:52

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}}))

credulous15:11:14

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

credulous15:11:18

(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)

credulous15:11:10

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

credulous15:11:51

(thermal-availability is also a reagent atom)

mafcocinco20:11:00

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!

tavistock20:11:00

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

tavistock20:11:44

do like

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

mafcocinco20:11:35

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.

hlolli20:11:48

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

(r/adapt-react-class
   (withAlert
    (r/reactify-component
     (r/create-class
      {:reagent-render
then I call that function with hiccup, but I'm getting errors I bet someone here can see quickly where I'm off track?

hlolli21:11:42

ah got it

(defn x []
(r/reactify-component
   (withAlert
    (r/create-class
and call it
[:> (x)]
strange but it works.

hlolli21:11:01

anyway, I encourage looking at how reagent interops with a library like this https://github.com/schiehll/react-alert 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).

lilactown22:11:14

if interop with libraries like this is important to you, I would encourage you to check out a library I’ve been working on: https://github.com/Lokeh/hx

lilactown22:11:21

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

hlolli10:11:54

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

hlolli10:11:19

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