Created
August 19, 2013 23:11
-
-
Save aamedina/6275295 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (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