This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-06
Channels
- # announcements (2)
- # beginners (97)
- # boot (3)
- # cider (23)
- # clara (9)
- # cljs-dev (40)
- # cljsrn (6)
- # clojure (107)
- # clojure-finland (2)
- # clojure-india (3)
- # clojure-italy (15)
- # clojure-nl (2)
- # clojure-spec (107)
- # clojure-uk (91)
- # clojurescript (28)
- # cursive (10)
- # data-science (4)
- # datomic (26)
- # duct (1)
- # emacs (6)
- # events (9)
- # figwheel-main (4)
- # fulcro (4)
- # graphql (2)
- # jobs (3)
- # jobs-discuss (12)
- # juxt (7)
- # kaocha (6)
- # off-topic (8)
- # onyx (2)
- # parinfer (13)
- # pedestal (32)
- # portkey (1)
- # re-frame (58)
- # reagent (17)
- # reitit (21)
- # ring-swagger (3)
- # shadow-cljs (35)
- # spacemacs (1)
- # tools-deps (33)
- # yada (13)
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}}))
(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?
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
(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?ah got it
(defn x []
(r/reactify-component
(withAlert
(r/create-class
and call it
[:> (x)]
strange but it works.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).
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
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