Created
June 10, 2014 11:35
-
-
Save kurogelee/5c69b5dfa2f219dcc79b to your computer and use it in GitHub Desktop.
defuiとCrate(Hiccup)メモ ref: http://qiita.com/kurogelee/items/59a5caae5e7b0c3571ad
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
"<div>:sample</div>" | |
"<div style=\"color:red; margin: 5px\"></div>" | |
"<div style=\"color:red; margin: 5px\">123</div>" |
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
"<button><div id=\"abc\"><span class=\"def\">987</span></div></button>" |
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 defui [sym params hiccup & events] | |
`(defn ~sym ~params | |
(let [e# (crate.core/html ~hiccup)] | |
(doseq [[ev# func#] (partition 2 ~(vec events))] | |
(lt.util.dom/on e# ev# func#)) | |
e#))) |
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
(defn ->ev [ev] | |
(str (name ev))) | |
(defn on [elem ev cb] | |
(.addEventListener elem (->ev ev) cb)) |
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
(ns sample.core | |
(:require [lt.util.dom :as dom]) | |
(:require-macros [lt.macros :refer [behavior defui]])) | |
(defui create-div [text] | |
[:div [:div text]]) | |
(.-innerHTML (create-div :sample)) | |
(defui create-div2 [& [value]] | |
[:div [:div {:style "color:red; margin: 5px"} value]]) | |
(.-innerHTML (create-div2)) | |
(.-innerHTML (create-div2 123)) |
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
(defui create-div3 [] | |
[:button [:div#abc [:span.def 987]]] | |
:click (fn [event] (println event))) | |
(.-outerHTML (create-div3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment