1- # ` expressions `
1+ = `expressions`
22
3- > Clojure to Datastar expression transpiler
3+ ____
4+ Clojure to Datastar expression transpiler
5+ ____
46
5- ` expressions ` is a proof-of-concept for writing [ 🚀 datastar] [ dt ] expressions using Clojure without manual string concatenation.
7+ `expressions` is a proof-of-concept for writing https://data-star.dev[🚀
8+ datastar] expressions using Clojure without manual string concatenation.
69
710Instead of:
811
9- ``` clojure
12+ [source,clojure]
13+ ----
1014[:button {:data-on-click (str "$person-id" (:id person) " @post('/update-person')")}]`
11- ```
12-
15+ ----
1316
1417Write this:
1518
16- ``` clojure
19+ [source,clojure]
20+ ----
1721[:button {:data-on-click (->expr
1822 (set! $person-id ~(:id person))
1923 (@post "/update-person"))}]
20- ```
24+ ----
2125
22- It is powered by [ squint] ( https://github.com/squint-cljs/squint ) , thanks [ @borkdude ] [ bork ] .
26+ It is powered by https://github.com/squint-cljs/squint[squint], thanks
27+ https://github.com/borkdude[@borkdude].
2328
24- ## Goal & Non-Goals
29+ == Goal & Non-Goals
2530
26- Since Clojure does not have string interpolation, writing even simple [ Datastar
27- (d\* ) expressions] [ dt-expr ] can involve a lot of ` str ` or ` format ` gymnastics.
31+ Since Clojure does not have string interpolation, writing even simple
32+ https://data-star.dev/guide/datastar_expressions[Datastar (d++*++)
33+ expressions] can involve a lot of `str` or `format` gymnastics.
2834
29- The goal of ` expressions ` is to add a little bit of syntax sugar when writing
30- d\* expressions so that they can be read and manipulated as s-expressions.
35+ The goal of `expressions` is to add a little bit of syntax sugar when
36+ writing d++*++ expressions so that they can be read and manipulated as
37+ s-expressions.
3138
32- D\* expressions are not exactly javascript, though they are interpreted by the
33- js runtime. D\* expressions also do not have a grammar or really any formal
34- definition of any kind. Delaney's official position is that the simplest
35- and obvious expressions a human would write should work.
39+ D++*++ expressions are not exactly javascript, though they are
40+ interpreted by the js runtime. D++*++ expressions also do not have a
41+ grammar or really any formal definition of any kind. Delaney’s official
42+ position is that the simplest and obvious expressions a human would
43+ write should work.
3644
37- ` expressions ` follows that by trying to provide coverage for 99% of simple and
38- obvious expressions.
45+ `expressions` follows that by trying to provide coverage for 99% of
46+ simple and obvious expressions.
3947
40- ⚠️ You can totally write expressions that result in broken javascript, that is not
41- necessarily a bug.
48+ ⚠️ You can totally write expressions that result in broken javascript,
49+ that is not necessarily a bug.
4250
43- ## Install
51+ == Install
4452
45- ``` clojure
53+ [source,clojure]
54+ ----
4655datastar/expressions {:git/url "https://github.com/outskirtslabs/datastar-expressions/"
4756 :git/sha "53efc7093be1ba33b331b4a27884be8925d8bdce"}
48- ```
57+ ----
4958
50- ## Status
59+ == Status
5160
52- ` expressions ` is experimental and breaking changes will occur as it is actively being developed. Please share your feedback so we can squash bugs and arrive at a stable release.
61+ `expressions` is experimental and breaking changes will occur as it is
62+ actively being developed. Please share your feedback so we can squash
63+ bugs and arrive at a stable release.
5364
54- ## REPL Exploration
65+ == REPL Exploration
5566
56- To see what this is all about, you can clone this repo and play with the demos:
67+ To see what this is all about, you can clone this repo and play with the
68+ demos:
5769
58- ```
70+ ....
5971clojure -M:dev ;; (bring your own repl server)
60- ```
61-
62- Check out [ ` dev/user.clj ` ] ( ./dev/user.clj ) and [ ` dev/demo.clj ` ] ( ./dev/demo.clj )
72+ ....
6373
74+ Check out link:./dev/user.clj[`dev/user.clj`] and
75+ link:./dev/demo.clj[`dev/demo.clj`]
6476
65- ## Example Usage
77+ == Example Usage
6678
67- ``` clojure
79+ [source,clojure]
80+ ----
6881(ns user
6982 (:require [starfederation.datastar.clojure.expressions :refer [->expr]]))
7083
@@ -230,11 +243,12 @@ Check out [`dev/user.clj`](./dev/user.clj) and [`dev/demo.clj`](./dev/demo.clj)
230243(->expr (when false
231244 (set! $foo true)))
232245;; => "((!!(false)) ? (($foo = true)) : (null))"
233- ```
246+ ----
234247
235- ## Known Limitations
248+ == Known Limitations
236249
237- ``` clojure
250+ [source,clojure]
251+ ----
238252;; a generated symbol (el-id below) cannot be used in a template string
239253(->expr (let [el-id evt.srcElement.id]
240254 (when el-id
@@ -246,18 +260,10 @@ Check out [`dev/user.clj`](./dev/user.clj) and [`dev/demo.clj`](./dev/demo.clj)
246260 true (set! $ui._mainMenuOpen false)
247261 false (set! $ui._mainMenuOpen true)))
248262;; => "(() => { const pred__288831 = squint_core._EQ_; const expr__288842 = $ui._mainMenuOpen; if (!!(pred__288831(true, expr__288842))) { return $ui._mainMenuOpen = false} else { if (!!(pred__288831(false, expr__288842))) { return $ui._mainMenuOpen = true} else { throw new java.lang.IllegalArgumentException(squint_core.str(\"No matching clause: \", expr__288842))}}; })()"
249- ```
250-
251- ## License: MIT License
252-
253- Copyright © 2025 Casey Link < casey@outskirtslabs.com >
254-
255- Distributed under the [ MIT] ( https://spdx.org/licenses/MIT.html ) .
256-
263+ ----
257264
258- [ bork ] : https://github.com/borkdude
259- [ dt ] : https://data-star.dev
260- [ dt-dev ] : https://github.com/starfederation/datastar/tree/develop
261- [ dt-expr ] : https://data-star.dev/guide/datastar_expressions
265+ == License: MIT License
262266
267+ Copyright © 2025 Casey Link casey@outskirtslabs.com
263268
269+ Distributed under the https://spdx.org/licenses/MIT.html[MIT].
0 commit comments