This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-04
Channels
- # announcements (25)
- # babashka (7)
- # beginners (52)
- # calva (29)
- # clara (1)
- # clj-kondo (4)
- # cljs-dev (55)
- # clojure (86)
- # clojure-europe (5)
- # clojure-finland (1)
- # clojure-france (1)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-uk (57)
- # clojurescript (33)
- # conjure (107)
- # cursive (20)
- # datomic (37)
- # emacs (23)
- # events (13)
- # fulcro (67)
- # helix (73)
- # jobs-discuss (22)
- # lambdaisland (1)
- # leiningen (32)
- # malli (2)
- # meander (9)
- # mid-cities-meetup (1)
- # observability (1)
- # off-topic (14)
- # overtone (3)
- # pathom (39)
- # re-frame (22)
- # reagent (13)
- # reitit (13)
- # shadow-cljs (52)
- # sql (15)
- # tools-deps (29)
- # vim (11)
I just realized that something that was simple in js, I don't know how to do it in clojurescript
anyone uses shadow-cljs? is there a way to hack the dependencies so that helix when requires react and react-dom, I can instead specify a different version for it to use? đ
I want to use helix with https://reactjs.org/docs/concurrent-mode-adoption.html I am not very happy about this separation of versions, but what to do
"all that", "that", I find it hard to understand what "that" exactly is in each case : ) Could you elaborate please?
Helix doesnât come into it - itâs shadow CLJS which uses whatever is in node_modules
it's another thing that shadow-cljs provides this under the name of react, but if it wouldn't be a predefined name, it would be nicer, so I could have whatever version used
since otherwise I would have to constantly update the build config for something that is business logic in this case, which version I am demoing
so, I am getting errors with the experimental build, and I am not sure why. Has anyone tried to use helix with react@experimental before?
as for using helix with a package of a different name than React, Iâm not sure how to support that
most errors are due to installing mismatching versions - e.g. you install react@experimental
but donât install react-dom@experimental
and react-refresh@experimental
(if youâre using react-refresh)
FWIW install the experimental versions should just work - thereâs no additional config required. if you for some reason want multiple versions of React on the same web page at the same time, I donât know how to do that
You can alias package names with shadow-cljs, e,g., I use it for react-native-web:
:js-options {:resolve {"react-native" {:target :npm
:require "react-native-web"}}}
@alidcastano that does work but it works for all packages overall the same way, can't specifically resolve different versions for different dependencies
one thing I would like to ask a bit of help before I go back to the experimental build, is how to use the progress channel of cljs-http with helix. Is there an idiomatic way to read in a use-effect or something from the channel?
if you need a useEffect to run every time just donât pass dependencies array as second argument
That's not an answer to my specific question. I get how react works, I have trouble using cljs http channels
@ashnur i donât think youâd ever want two* versions of react running at same time. specially with hooks, that will cause nasty errors
also, I don't want to use different react versions TOGETHER, I want to use them in the same app. That's not together. : ) but I have since got help in #shadow-cljs that it's better to have separated builds, so I completely given up on that idea, I will not complicate my life by fighting the tooling. (It's worth mentioning though how limiting is when people assume they know what others want or might or might not want : D)
Iâd have to think more about it. for one-shot requests you might be able to do:
(let [[response set-response] (hooks/use-state nil)]
(hooks/use-effect
:once
(go (-> (<! (http/get "api"))
(set-response))))
,,,)
simpler than setting up a go loop, but probably not what I should use for the progress events
(defhook use-take
[channel on-take]
(let [cancel-signal (hooks/use-ref false)]
(hooks/use-effect
[channel on-take]
(go-loop []
(if-not @cancel-signal
(do (on-take (<! channel))
(recur))
(reset! cancel-signal false)))
#(reset! cancel-signal true))))
yeah, in use-effect
you can return a function that runs when the dependencies change, or the component is unmounted
note I havenât tested that at all đ so might not quite work. but itâs the general idea
it's very useful, i was looking for some proper way to loop only when actually something happens, I just need to read the docs about these functions
Ok, so I don't get the else clause for the if-not. That should only ever be true after the hook was unmounted, but at that point I just want it to be garbage collected, a new element mounted will use a new hook anyway. In fact, what I would rather do somewhere is to check if the channel is closed and escape the loop then
yeah, the else clause is there to cleanup when either the channel changes, the on-take
function changes, or the component unmounts
if it hits that branch, then itâs because the effect has run the cleanup function
but the go-loop
will still be running, which is why we check for the cancel-signal
and if itâs true
, donât recur
for example, if we naively did
(go-loop []
(do (on-take (<! channel))
(recur)))
then even once the effect cleaned up, it would still be running the go-loop and it wouldnât be garbage collectedhttps://gist.github.com/ashnur/c336b998fbc5d7c7580aa52fe9e827f7 this is how I would expect it to work naively đ
my thinking was that, if you pass in a new on-take
function, you want to stop your go-loop
and start another go-loop
using the new function
so in that case, you want to have your current go-loop
see the cancel-signal, and then reset it so the new one will start
calling the use-take hook a second time should create a new loop entirely imho, it's a new scope, new context, new bindings