This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-24
Channels
- # announcements (3)
- # babashka (47)
- # beginners (40)
- # biff (21)
- # calva (12)
- # cider (2)
- # clj-kondo (31)
- # cljsrn (8)
- # clojure (14)
- # clojure-berlin (2)
- # clojure-conj (1)
- # clojure-dev (24)
- # clojure-europe (84)
- # clojure-italy (8)
- # clojure-nl (1)
- # clojure-spec (1)
- # clojure-sweden (2)
- # clojure-uk (2)
- # clojurescript (34)
- # clr (3)
- # community-development (1)
- # cursive (14)
- # datalevin (8)
- # datomic (5)
- # defnpodcast (2)
- # dev-tooling (1)
- # etaoin (4)
- # events (3)
- # fulcro (26)
- # graphql (3)
- # honeysql (6)
- # hyperfiddle (45)
- # lsp (40)
- # malli (1)
- # missionary (1)
- # nbb (18)
- # podcasts-discuss (1)
- # reagent (8)
- # reitit (2)
- # releases (2)
- # ring-swagger (1)
- # scittle (78)
- # shadow-cljs (96)
- # vim (7)
- # xtdb (3)
Is there a library for a "recursive" #js literal? So that one doesn't need to type #js {:nested #js {:objects #js ["like this"]}}
edit: preferably something that runs at compile time, like a macro
Haven't checked but should work:
(require '[cljs.tagged-literals :as cljs-tl]
'[clojure.walk :as walk])
(defmacro recursive-js [form]
(walk/postwalk (fn [value]
(cond-> value
(or (and (vector? value)
(not (map-entry? value)))
(map? value))
(cljs-tl/read-js)))
form))
Works pretty well so far… Just need to adapt it for closures and it’s perfect for my use case 🙂
welp, looks like functions will be tricky to get right, since once would need the ability to modify the code in-place and invoke the CLJS compiler to emit a javascript function — otherwise the postwalk will visit the arglist and convert that to JS objects… However. one workaround is to simply create bindings for functions and use that inside the data 😄
You can avoid going into functions by replacing the walk function with something that doesn't go inside lists. And also sets, I presume.
Also didn't check but also should work, this time without descending into any collections other than maps and vectors:
(require '[cljs.tagged-literals :as cljs-tl])
(defn -recursive-js [form]
(cond
(map? form) (cljs-tl/read-js (update-vals form -recursive-js))
(vector? form) (cljs-tl/read-js (mapv -recursive-js form))
:else form))
(defmacro recursive-js [form]
(-recursive-js form))
I'm using Tailwind in my Clojurescript frontend. How about the Tailwind CSS classes that have /
character in the classname (not a valid character in Clojure keywords)? E.g. how to provide this JSX snippet in Clojurescript/Hiccup? ( w-1/2
):
<div className="flex grow w-1/2">
Ah, of course. 🙂
It has been some time since I previously wrote Clojurescript / Hiccup. 🙂
Although it's very strange that they decided to use /
in the first place. AFAICT, it's not a valid symbol for a class name, even though browsers seem to support it. Some people do experience problems with it, e.g. https://github.com/tailwindlabs/tailwindcss/issues/1973
Seems like there's a way to replace it with something else on a per-project basis though.
Ah, I'm actually wrong - in CSS3 selectors, there are limits and you have to escape a lot. But in HTML5 you can use slashes just fine, it seems.
Thanks!
Hello, I'm trying to use (.open js/window "some url")
to open a new window. When I run it from development, it works, but after deploying it, not working. Is there any issue in production env for that?
browsers usually aren't eager about letting you open new windows, so generally the open is only allowed as part of a click or so
There might be a tiny icon in the address bar that, if you hover over it, will say that the website tried to open other windows.
Also, I'm pretty sure you can use (js/open "some url")
, without js/window
. But it's the same function.
Hello! Is there some article, paper, video on how the clojurescript compilation process works?
@UPJP9G4G1 one thing that is maybe helpful if you are trying to understand how the clojurescript compiler works it is to run it under FlowStorm(https://github.com/jpmonettas/flow-storm-debugger) This big "one liner"
clj -Sdeps '{:deps {com.github.jpmonettas/flow-storm-dbg {:mvn/version "3.3.320"} org.clojure/clojurescript {:mvn/version "1.11.60"}}}' -X flow-storm.api/cli-run :instrument-ns '#{"cljs."}' :profile ':light' :flow-id 0 :require-before '#{"cljs.repl.node"}' :excluding-ns '#{"cljs.core"}' :fn-symb 'cljs.main/-main' :fn-args '["-t" "nodejs" "/home/user/cljs-test/src/org/foo/myscript.cljs"]';
will open the debugger, instrument the clojurescript compiler and then compile a example cljs file you give it /home/user/cljs-test/src/org/foo/myscript.cljs
in this case, assuming you are interested in understanding how that file gets compiled.
Here is a video showing a little bit on FlowStorm exploring the ClojureScript compiler:
https://youtu.be/A3AzlqNwUXc?t=1945
In the video case the myscript.cljs
is something like this
(ns org.foo.myscript)
(defn factorial [n]
(if (zero? n)
1
(* n (factorial (dec n)))))
(js/console.log "Factorial of 5 is :" (factorial 5))
I found this video by Maria very insightful. She did some work on the clojurescript compiler. https://www.youtube.com/watch?v=Elg17s_nwDg
I haven't watched this video but I had bookmarked this three hour video of a session with mike fikes on the clojurescript compiler https://www.youtube.com/watch?v=kBKIGj1_WAo