From 0f2136d4b4dcae172b2d6f763f4f12d330a910a5 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Tue, 18 Mar 2014 16:43:19 +0100 Subject: [PATCH] Allow render-component to take a function returning a component --- examples/simple/Makefile | 1 + examples/simple/project.clj | 2 +- examples/simple/src/simpleexample.cljs | 2 +- src/reagent/core.cljs | 4 +++- src/reagent/impl/util.cljs | 5 ++--- test/runtests.cljs | 3 ++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/simple/Makefile b/examples/simple/Makefile index 9495bda..74dca32 100644 --- a/examples/simple/Makefile +++ b/examples/simple/Makefile @@ -14,6 +14,7 @@ openbrowser: (sleep 1 && open example.html) & autocompile: + rm -rf target lein with-profile $(PROF) cljsbuild auto $(CLJSBUILD) clean: diff --git a/examples/simple/project.clj b/examples/simple/project.clj index 5069f09..fd672e9 100644 --- a/examples/simple/project.clj +++ b/examples/simple/project.clj @@ -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 diff --git a/examples/simple/src/simpleexample.cljs b/examples/simple/src/simpleexample.cljs index 2a3daf3..7d6ac69 100644 --- a/examples/simple/src/simpleexample.cljs +++ b/examples/simple/src/simpleexample.cljs @@ -33,5 +33,5 @@ [color-input]]) (defn ^:export run [] - (reagent/render-component [simple-example] + (reagent/render-component (fn [] [simple-example]) (.-body js/document))) diff --git a/src/reagent/core.cljs b/src/reagent/core.cljs index 84962c9..70574e2 100644 --- a/src/reagent/core.cljs +++ b/src/reagent/core.cljs @@ -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." diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index db7f394..3b8beb0 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -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) diff --git a/test/runtests.cljs b/test/runtests.cljs index 8674360..fa8e724 100644 --- a/test/runtests.cljs +++ b/test/runtests.cljs @@ -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 "-----------------------------------------")