Created
February 12, 2023 17:07
-
-
Save LouDnl/82b4020555afaf322a3381525451052d to your computer and use it in GitHub Desktop.
Clojure hiccup with inline scittle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[:div "SCITTLE JS"] | |
[:div#scittle-test | |
[:script {:type "application/x-scittle"} | |
(pr-str | |
'(defn my-alert [] | |
(js/alert "You clicked! ")) | |
;; export function to use from JavaScript: | |
'(set! (.-my_alert js/window) my-alert))]] | |
[:div | |
[:button.text-white.shadow.rounded.btn.bg-success.bg-gradient.border-info {:onclick "my_alert()"} | |
[:svg.bi.bi-exclamation-triangle.text-success {:width "32" :height "32" :fill "currentColor" :viewBox "0 0 16 16" :xmlns "http://www.w3.org/2000/svg" }]]] | |
[:svg.bi.bi-exclamation-triangle.text-success {:width "32" :height "32" :fill "black" :viewBox "0 0 16 16" :xmlns "http://www.w3.org/2000/svg"}] | |
[:p] | |
[:div "SCITTLE REAGENT"] | |
[:div#app] | |
[:div#scittlereagent-test | |
[:script {:type "application/x-scittle"} | |
(pr-str | |
'(require '[reagent.core :as r] | |
'[reagent.dom :as rdom]) | |
'(def state (r/atom {:clicks 0})) | |
'(defn my-component [] | |
[:div | |
[:p "Clicks: " (:clicks @state)] | |
[:p [:button.text-white.btn.bg-danger.bg-gradient {:on-click #(swap! state update :clicks inc)} | |
"Click me!"]]]) | |
'(rdom/render [my-component] (.getElementById js/document "app")))]] | |
[:p] | |
[:div "SCITTLE AJAX"] | |
[:div#scittleajax-test | |
[:script {:type "application/x-scittle"} | |
(pr-str | |
'(require '[ajax.core :refer [GET]]) | |
'(defn handler [response] | |
(js/alert (str response))) | |
'(defn make-request [] | |
(GET "/" {:handler handler})) | |
;; export function to use from JavaScript: | |
'(set! (.-make_request js/window) make-request))]] | |
[:div | |
[:button.text-white.btn.bg-warning.bg-gradient {:onclick "make_request()"} "Click Me!"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment