-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.clj
45 lines (40 loc) · 1.66 KB
/
index.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(ns index
(:require [babashka.deps :as deps]
[hiccup2.core :as h]
[org.httpkit.server :as srv]
[cheshire.core :as json]))
(deps/add-deps '{:deps {io.github.squint-cljs/squint {:local/root "../.."}}})
(require '[squint.compiler :as squint])
(def state (atom nil))
(defn ->js [form]
(let [res (squint.compiler/compile-string* (str form))]
(reset! state res)
(:body res)))
(defn page [_]
{:body (str (h/html
[:html
[:head
[:link {:rel "stylesheet"
:href "https://cdn.jsdelivr.net/npm/water.css@2/out/light.css"}]
[:script {:type "importmap"}
(h/raw
(json/generate-string
{:imports
{"squint-cljs/src/squint/core.js" "https://cdn.jsdelivr.net/npm/[email protected]/src/squint/core.js"}}))]
[:script {:type "module"}
(h/raw
"globalThis.squint_core = await import('squint-cljs/src/squint/core.js');")]
[:title "Squint"]]
[:body
[:div "Click the button to update counter!"]
[:button
{:onclick (->js '(let [elt (js/document.getElementById "counter")
val (-> (.-innerText elt) parse-long)]
(set! elt -innerText (inc val))))}
"Click me"]
[:div "The counter value:"
[:span {:id "counter"} "0"]]]]))
:status 200})
(srv/run-server #'page {:port 8888})
(println "Server started at http://localhost:8888")
@(promise)