Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 19, 2013 23:11
Show Gist options
  • Select an option

  • Save aamedina/6275295 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6275295 to your computer and use it in GitHub Desktop.
(defmacro compile-events
[events]
(let [handlers (vals events)
compiled-handlers
(for [handler handlers]
(let [func (into (list) (reverse (cons 'defn (cons 'e (rest handler)))))]
(-> (build func {:optimizations :advanced})
(clojure.string/replace #"^.*=" "var tmp=")
(clojure.string/replace #";$" "; tmp;"))))]
(json/write-str (zipmap (keys events) compiled-handlers))))
(defhtml dashboard
[req user]
[:div.page-header
[:h1 "Datasift" [:small " dashboard"]]]
[:div
[:p
[:button
{:data-event
(compile-events
{:click
(fn [e]
(println "hello there client, i'm the server!" "don't be frightened..."))})}
"Click me!"]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment