This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-14
Channels
- # admin-announcements (1)
- # announcements (28)
- # babashka (9)
- # beginners (32)
- # biff (1)
- # calva (1)
- # clj-kondo (26)
- # clj-otel (52)
- # cljs-dev (2)
- # clojure (41)
- # clojure-europe (23)
- # clojure-korea (7)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojure-uk (4)
- # community-development (10)
- # core-typed (9)
- # cursive (2)
- # datahike (8)
- # events (1)
- # helix (10)
- # kaocha (5)
- # malli (14)
- # missionary (4)
- # off-topic (42)
- # pedestal (1)
- # reagent (3)
- # releases (5)
- # shadow-cljs (33)
- # squint (18)
- # tools-build (8)
- # xtdb (17)
Question about shadow wrt Cloudflare: is there a way to (:require ["cloudflare:workers" :refer [DurableObject]])
such that JS import
statement is emitted for "cloudflare:workers"
require?
Also shadow should not try to resolve the dependency since it's injected at runtime in CF env
depending on which the answer is either :js-options {:keep-as-require #{"cloudflare:workers"}}
or :keep-as-import
(e.g. for :esm
)
Whichever is better really. Should I use :esm
?
Hm, when I use target :esm
, it seems to be compiling fine, but then CF complains about eval
▲ [WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]
out/cljs-runtime/shadow.dom.js:1439:0:
1439 │ eval(script_body_45595);
actually those are just warnings, the actual error is this one
✘ [ERROR] service core:user:realtime2: Uncaught Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler.
at null.<anonymous> (main.js:81002:219) in shadow$cljs$devtools$client$shared$init_runtime_BANG_
at null.<anonymous> (main.js:82802:42) in
out/cljs-runtime/shadow.cljs.devtools.client.browser.js
at null.<anonymous> (main.js:11:50) in __require
at null.<anonymous> (main.js:86256:58)
hmm, out/cljs-runtime/shadow.cljs.devtools.client.browser.js
suggests that shadow loads browser runtime here, but it's not relevant for me since the script is loaded into CF runtime
so I guess what I need is esm+node-script
or something
never looked at cloudflare stuff, so dunno what would be best but definitely not :browser
😛
possibly even :js-options {:js-provider :import}
and letting their tools take care of bundling all JS deps https://shadow-cljs.github.io/docs/UsersGuide.html#_third_party_tool_integration
just remember that I actually did look at it before 😛 https://github.com/thheller/cljs-cf-worker
nice, disabling devtools works!
Today I solved the advanced compilation problem i. But I can not explain why the code is now properly compiled.
(defn polygon->array [^js polygon-ref]
;; ------------------
;; there is a compiler warning, when all in one expression
#_(some->> polygon-ref
.-current
.-state
.-polygon
.getPath
.getArray
(map (fn [ll] [(.lat ll) (.lng ll)])))
;; ------------------ this part is ok
(let [^js polygon (some-> polygon-ref
.-current
.-state
.-polygon)
_ (set! js/ppp polygon) ;; checked on console, there are .getPath and .getArray
;; -- but this part must be evaluated separately
#_#_coor-ring (some->> polygon
.getPath
.getArray
(map (fn [ll] [(.lng ll) (.lat ll)])))
;; this works
^js pp (.getPath polygon)
arr (.getArray pp)
coor-ring (map (fn [ll] [(.lng ll) (.lat ll)]) arr)
;; this is not problematic
f (first coor-ring)
coor-ring (if (not= f (last coor-ring))
(concat coor-ring [f])
coor-ring)]
(into [] coor-ring)))
No, I did for the first version. But polygon-ref (hooks/use-ref ) is ^js tagged. (some->> polygon-ref .-current .-state .-polygon .getPath .getArray (map (fn [ll] [(.lat ll) (.lng ll)])))
I don't think I have ever used some->>
, so could be that it maybe not properly propagates the ^js
tag
is there a way how to check if ^js is propagated, sometjong like assert-js, or spy-js? so it can be injected in thread macros. (some->> polygon-ref .-current .-state .-polygon .getPath .getArray `spy-js` (map (fn [ll] [(.lat ll) (.lng ll)])))
or if you insist you can take this over to http://ask.clojure.org and turn it into a proper ticket for CLJS itself
you are right, some-> is problematic, but it is strange, that in my case real case code is compiled without warning. I can not reproduce it in a simple case. But it is a surprise, that I have to tag towel to compile in the first expression. and symbols must have a bit longer names to trigger minification. (let [`^js` towel (`clj->js` {:aaaaa {:bbbbb {:ccccc {:ddddd 42}}}})] (pr-str [(-> towel .-aaaaa .-bbbbb .-ccccc .-ddddd) (->> towel .-aaaaa .-bbbbb .-ccccc .-ddddd) #_(some-> towel .-aaaaa .-bbbbb .-ccccc .-ddddd) #_(some->> towel .-aaaaa .-bbbbb .-ccccc .-ddddd)]))
towel is javascript object towel.aaaaa.bbbbb.ccccc.ddddd === 42
and then i am extracing 42 with 4 macros
towel is not recognized as ^js but it is created by clj->js