Add docs for create-element, and one-argument version

And add a fix for the benefit of Light Table
This commit is contained in:
Dan Holmsand 2014-12-07 20:26:29 +01:00
parent 6e8a5178b3
commit fc2c59c3e1
3 changed files with 18 additions and 1 deletions

View File

@ -26,6 +26,7 @@
:dev-base {:dependencies
[[figwheel "0.1.5-SNAPSHOT"]]
:plugins [[lein-figwheel "0.1.5-SNAPSHOT"]]
:source-paths ["demo"] ;; for lighttable
:resource-paths ["site" "outsite"]
:figwheel {:css-dirs ["site/public/css"]}
:cljsbuild {:builds

View File

@ -12,7 +12,21 @@
(def is-client util/is-client)
(defn create-element
"Create a native React element, by calling React.createElement directly."
"Create a native React element, by calling React.createElement directly.
That means the second argument must be a javascript object (or nil), and
that any Reagent hiccup forms must be processed with as-element. For example
like this:
(r/create-element \"div\" #js{:className \"foo\"}
\"Hi \" (r/as-element [:strong \"world!\"])
which is equivalent to
[:div.foo \"Hi\" [:strong \"world!\"]]
"
([type]
(create-element type nil))
([type props]
(assert (not (map? props)))
(js/React.createElement type props))

View File

@ -412,6 +412,8 @@
(deftest test-create-element
(let [ae reagent/as-element
ce reagent/create-element]
(is (= (rstr (ae [:div]))
(rstr (ce "div"))))
(is (= (rstr (ae [:div]))
(rstr (ce "div" nil))))
(is (= (rstr (ae [:div "foo"]))