Allow render-component to take a function returning a component

This commit is contained in:
Dan Holmsand 2014-03-18 16:43:19 +01:00
parent ba995c2e0d
commit 0f2136d4b4
6 changed files with 10 additions and 7 deletions

View File

@ -14,6 +14,7 @@ openbrowser:
(sleep 1 && open example.html) &
autocompile:
rm -rf target
lein with-profile $(PROF) cljsbuild auto $(CLJSBUILD)
clean:

View File

@ -3,7 +3,7 @@
(defproject simple-reagent "0.4.2"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2173"]
[reagent "0.4.2"]]
[reagent "0.4.3-SNAPSHOT"]]
:plugins [[lein-cljsbuild "1.0.2"]]
:hooks [leiningen.cljsbuild]
:profiles {:prod {:cljsbuild

View File

@ -33,5 +33,5 @@
[color-input]])
(defn ^:export run []
(reagent/render-component [simple-example]
(reagent/render-component (fn [] [simple-example])
(.-body js/document)))

View File

@ -28,7 +28,9 @@ Returns the mounted component instance."
([comp container]
(render-component comp container nil))
([comp container callback]
(util/render-component (as-component comp) container callback)))
(let [f (fn []
(as-component (if (fn? comp) (comp) comp)))]
(util/render-component f container callback))))
(defn unmount-component-at-node
"Remove a component from the given DOM node."

View File

@ -128,7 +128,7 @@
(defn re-render-component [comp container]
(try
(odo React :renderComponent comp container)
(odo React :renderComponent (comp) container)
(catch js/Object e
(do
(try
@ -141,8 +141,7 @@
(throw e)))))
(defn render-component [comp container callback]
(odo React :renderComponent
comp container
(odo React :renderComponent (comp) container
(fn []
(let [id (get-root-id container)]
(when-not (nil? id)

View File

@ -35,7 +35,8 @@
[demo/demo]])
(defn ^:export mounttests []
(reagent/render-component [test-demo] (.-body js/document)))
(reagent/render-component (fn [] [test-demo])
(.-body js/document)))
(defn ^:export run-all-tests []
(println "-----------------------------------------")