diff --git a/src/reagent/core.cljs b/src/reagent/core.cljs index d116c11..3c8d28e 100644 --- a/src/reagent/core.cljs +++ b/src/reagent/core.cljs @@ -72,7 +72,7 @@ looking like this: Everything is optional, except :render. " [spec] - (tmpl/create-class spec)) + (comp/create-class spec)) (defn current-component diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 36d30b3..0c700fd 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -29,6 +29,8 @@ (defn set-state [this new-state] (swap! (state-atom this) merge new-state)) +;; set from template, to avoid circular deps +(def as-component nil) ;;; Rendering @@ -49,7 +51,7 @@ 5 (f (nth argv 1) (nth argv 2) (nth argv 3) (nth argv 4)) (apply f (subvec argv 1)))))] (if (vector? res) - (.' c asComponent res) + (as-component res) (if (ifn? res) (do (.! c :cljsRender res) @@ -189,10 +191,9 @@ map-to-js)) (defn create-class - [body as-component] + [body] (assert (map? body)) (let [spec (cljsify body) - _ (.! spec :asComponent (dont-bind as-component)) res (.' js/React createClass spec) f (fn [& args] (as-component (apply vector res args)))] diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 2bcff38..cc7703c 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -185,12 +185,10 @@ (def cached-wrapper (util/memoize-1 get-wrapper)) -(declare create-class) - (defn fn-to-class [f] (let [spec (meta f) withrender (assoc spec :component-function f) - res (create-class withrender) + res (comp/create-class withrender) wrapf (util/cached-react-class res)] (util/cache-react-class f wrapf) wrapf)) @@ -248,8 +246,8 @@ (expand-seq x)) true x)) -(defn create-class [spec] - (comp/create-class spec as-component)) +;; Cheat, to avoid ugly circular dependency +(set! reagent.impl.component/as-component as-component) (defn expand-seq [s] (let [a (into-array s)]