This commit is contained in:
Adam Jeniski 2025-07-21 09:04:13 -09:00
parent 32fcf7a6e9
commit 59ad03f123
2 changed files with 22 additions and 22 deletions

View File

@ -21,27 +21,27 @@
;; pages
(defpage home-page
(html->str
[:main
[:div
[:input {:data-bind "msg"}]
[:div {:data-text "$msg"}]
[:button {:data-on-click (->expr (@post ~hello-world ~keep-open))}
"click for text animation"]]
[:button {:data-on-click (->expr (@post ~page-2))}
"go to page 2"]]))
(html->str
[:main
[:div
[:input {:data-bind "msg"}]
[:div {:data-text "$msg"}]
[:button {:data-on-click (->expr (@post ~hello-world ~keep-open))}
"click for text animation"]]
[:button {:data-on-click (->expr (@post ~page-2))}
"go to page 2"]]))
(defpage page-2
(html->str
[:main
[:div
[:main
[:div
[:p "this is page2"]
[:button
{:data-on-click (->expr (@post ~say-hi))}
"say hi to everyone"]]
[:button {:data-on-click (->expr (@post ~home-page))}
"go back to home"]]))
[:button {:data-on-click (->expr (@post ~home-page))}
"go back to home"]]))
;; http app server
(def routes

View File

@ -142,21 +142,21 @@
(defn app-routes
([]
(->> @!ma-routes
vec))
(->> @!ma-routes
vec))
([index-route]
(concat (app-routes)
[["/" (@!ma-routes index-route)]])))
[["/" (@!ma-routes index-route)]])))
(defmacro defaction [action-sym args & body]
(let [url (str "/sse/" action-sym)]
`(let [sse-handler#
(fn [request# respond# raise_#]
(respond#
(respond#
(->sse-response
request#
{on-open (fn ~args (d*/with-open-sse ~(get args 0)
~@body))})))]
request#
{on-open (fn ~args (d*/with-open-sse ~(get args 0)
~@body))})))]
(add-route! ~url sse-handler#)
(def ~action-sym ~url))))