61 lines
1.4 KiB
Clojure
61 lines
1.4 KiB
Clojure
(ns example.core
|
|
(:require
|
|
[example.utils :refer [html->str defpage defaction defaction-async] :as u]
|
|
[reitit.ring :as rr]
|
|
[ring.util.response :as ruresp]))
|
|
|
|
|
|
;; views
|
|
(defn home-view [_]
|
|
(html->str
|
|
[:main
|
|
[:div
|
|
[:input {:data-bind "msg"}]
|
|
[:div {:data-text "$msg"}]
|
|
[:button {:data-on-click "@get('/hello-world')"} "click for text animation"]]
|
|
[:button {:data-on-click "@get('/page2')"} "go to page 2"]]))
|
|
|
|
|
|
(defn page2-view [_]
|
|
(html->str
|
|
[:main
|
|
[:p "this is page2"]
|
|
[:button {:data-on-click "@get('/')"} "go back to home"]]))
|
|
|
|
;; hello world animation
|
|
(def message "Hello, world!")
|
|
|
|
(def msg-count (count message))
|
|
|
|
(defn hello-world [sse]
|
|
(dotimes [i msg-count]
|
|
(u/patch-signals-edn! sse {:msg (subs message 0 (inc i))})
|
|
(Thread/sleep 500)))
|
|
|
|
(def routes
|
|
(concat
|
|
(defpage "/" home-view)
|
|
(defpage "/page2" page2-view)
|
|
(defaction "/hello-world" hello-world)
|
|
(defaction-async "/connect" u/connect-sse! u/disconnect-sse!)))
|
|
|
|
(def router (rr/router routes))
|
|
|
|
(def handler (rr/ring-handler router))
|
|
|
|
|
|
;; repl it up ;P
|
|
(comment
|
|
(u/broadcast-signals! {:msg "hi franz"})
|
|
(u/broadcast-signals! {:msg "hi ty"})
|
|
(u/broadcast! d*/console-log! "hi franz")
|
|
(u/broadcast-js! "console.log('test')")
|
|
(u/broadcast-reload!)
|
|
|
|
(kill-broadcast!)
|
|
|
|
|
|
(clojure.repl/dir d*)
|
|
(clojure.repl/doc d*/patch-signals!))
|
|
|