mirror of https://github.com/status-im/reagent.git
Make workaround for circular dependency less cumbersome
This commit is contained in:
parent
b869f13a4e
commit
e4617bcaf6
|
@ -72,7 +72,7 @@ looking like this:
|
|||
Everything is optional, except :render.
|
||||
"
|
||||
[spec]
|
||||
(tmpl/create-class spec))
|
||||
(comp/create-class spec))
|
||||
|
||||
|
||||
(defn current-component
|
||||
|
|
|
@ -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)))]
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in New Issue