diff --git a/src/cloact/impl/component.cljs b/src/cloact/impl/component.cljs index dde9c6f..81827e2 100644 --- a/src/cloact/impl/component.cljs +++ b/src/cloact/impl/component.cljs @@ -208,6 +208,7 @@ (defn create-class [body] + (assert (map? body)) (let [spec (cljsify body) res (.createClass React spec) f (fn [& args] diff --git a/src/cloact/impl/template.cljs b/src/cloact/impl/template.cljs index 6592492..9f2aef3 100644 --- a/src/cloact/impl/template.cljs +++ b/src/cloact/impl/template.cljs @@ -32,7 +32,8 @@ [id class'])])) (def attr-aliases {"class" "className" - "for" "htmlFor"}) + "for" "htmlFor" + "charset" "charSet"}) (defn undash-prop-name [n] (let [undashed (dash-to-camel n)] @@ -114,6 +115,7 @@ (declare wrapper) (defn fn-to-class [f] + (assert (fn? f)) (let [spec (meta f) withrender (merge spec {:render f}) res (cloact.core/create-class withrender)] @@ -130,6 +132,7 @@ (fn-to-class x))))) (defn vec-to-comp [v] + (assert (pos? (count v))) (let [[tag props] v c (.-cljsReactClass (as-class tag)) obj (js-obj)] diff --git a/test/demo.cljs b/test/demo.cljs index 3bb2406..69d67a9 100644 --- a/test/demo.cljs +++ b/test/demo.cljs @@ -38,11 +38,12 @@ "range" "nil\\?" "int" "or" "->" "%"]) (defn syntaxify [src] + ;; quick and (very) dirty syntax coloring (let [sep "\\][(){} \\t\\n" str-p "\"[^\"]*\"" keyw-p (str ":[^" sep "]+") res-p (string/join "|" (map #(str "\\b" % "(?=[" sep "])") builtins)) - any-p (str "[^" sep "]+|.|\\n") ;; ".|\\n" + any-p (str "[^" sep "]+|.|\\n") patt (re-pattern (str "(" (string/join ")|(" [str-p keyw-p res-p any-p]) ")"))] @@ -54,18 +55,18 @@ res [:b res] :else s))))) -(defn src-for [{:keys [defs]}] +(defn src-for [defs] [:pre (syntaxify (src-for-names defs))]) -(defn demo-component [props] +(defn demo-component [{:keys [comp defs]}] [:div - (when (:comp props) + (when comp [:div.demo-example [:h3.demo-heading "Example"] - [(:comp props)]]) + [comp]]) [:div.demo-source [:h3.demo-heading "Source"] - [src-for props]]]) + (src-for defs)]]) (defn simple-component [] [:div @@ -165,7 +166,8 @@ [:div [:h2 "Introduction to Cloact"] - [:p "Cloact provides a minimalistic interface between " + [:p [:a {:href "https://github.com/holmsand/cloact"} "Cloact"] + " provides a minimalistic interface between " [:a {:href "https://github.com/clojure/clojurescript"} "ClojureScript"] " and " [:a {:href "http://facebook.github.io/react/"} "React"] ". It allows you to define React components using nothing but