This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-14
Channels
- # adventofcode (29)
- # aws (3)
- # babashka (25)
- # beginners (13)
- # calva (4)
- # cherry (7)
- # cider (26)
- # clj-kondo (9)
- # clojure (88)
- # clojure-europe (21)
- # clojure-losangeles (3)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (11)
- # clojuredesign-podcast (2)
- # clojurescript (4)
- # cursive (10)
- # datalevin (1)
- # emacs (50)
- # gratitude (1)
- # honeysql (12)
- # hyperfiddle (19)
- # jobs-discuss (28)
- # kaocha (3)
- # lsp (53)
- # malli (4)
- # meander (3)
- # off-topic (48)
- # re-frame (11)
- # releases (2)
- # ring-swagger (2)
- # shadow-cljs (50)
- # squint (26)
- # tools-build (3)
- # tools-deps (8)
- # xtdb (4)
- # yamlscript (1)
I am trying to use alpine.js, with squint. I can get it working by embedding strings of js (:face_vomiting:) in my hiccup. Some things require json (which is easy to produce) and others require some plain js expressions. e.g. just: “count--“. Can I produce an analog with squint? Fuller example in 🧵
This is a counter component in hiccup (https://github.com/escherize/huff actually), no processing going on:
(defn counter []
[:div {:x-data "{\"count\":0}"}
[:button {:x-on:click "count--"} "Decrement"]
[:button {:x-on:click "count++"} "Increment"]
[:h1 {:x-text "count"}]
[:div {:x-data "{\"words\":[\"Once\",\"upon\",\"a\",\"time,\"]}"
:x-text "words[count]"}]])
Same thing, with the json removed
(defn counter-json []
[:div {:x-data {:count 0}}
[:button {:x-on:click "count--"} "Decrement"]
[:button {:x-on:click "count++"} "Increment"]
[:h1 {:x-text "count"}]
[:div {:x-data (j {:words ["Once" "upon" "a" "time"]})
:x-text "words[count]"}]])
What I’d like to use:
(defn counter-want-one []
[:div {:x-data {:count 0}}
[:button {:x-on:click (compile
(fn [{:keys [count]}]
(set! count (dec count))))} "Decrement"]
[:button {:x-on:click (compile
(fn [{:keys [count]}]
(set! count (inc count))))} "Increment"]
[:h1 {:x-text "count"}]
[:div {:x-data (j {:words ["Once" "upon" "a" "time"]})
:x-text "words[count]"}]])
I made a bb hiccup example here with inline JS here: https://github.com/squint-cljs/squint/blob/main/examples/babashka/index.clj I'm not sure what the added value of squint + alpine.js is
I've got this working now:
[:body
[:div {:x-data (->js '{:counter 0})}
[:button {:x-on:click (->js '(set! counter (inc counter)))}
"Increment"]
[:span {:x-text "counter"}]]]
ok, this is what I've got right now: https://github.com/squint-cljs/squint/blob/main/examples/babashka/alpinejs.clj one problem is that when you remove the non-atom counter from x-text, you don't get a re-render
Using squint with Next.js seems to work nicely. Only one issue, for pure client components one option is to write “use client” on the first line but since squint imports itself on the first line it cannot be done. There are ways around that tho.
Good to hear! We can try to accommodate this better. I had similar problems with getting js-doc to work and putting a // ts-check
on the first line
That was fast! I will try out today. :sports_medal:
Works fine. Thank you!
🎉 Curious about an example next.js project, if you want to create one in the examples dir in the repo, feel free :)
Yeah sure. I think it would add some value. 👍