Don't use ilookup for props, children, etc.

This commit is contained in:
Dan Holmsand 2013-12-17 12:59:21 +01:00
parent 89e7392269
commit 9e5e38fbc7
7 changed files with 43 additions and 33 deletions

View File

@ -9,7 +9,7 @@ PROF = dev,test
CLJSBUILD = client CLJSBUILD = client
CLJSDIRS = src test CLJSDIRS = src test
VERSION = 0.0.1-SNAPSHOT VERSION = 0.0.2-SNAPSHOT
all: buildrun all: buildrun

View File

@ -1,8 +1,8 @@
(defproject simple-cloact "0.0.1" (defproject simple-cloact "0.0.2-SNAPSHOT"
:dependencies [[org.clojure/clojurescript "0.0-2120"] :dependencies [[org.clojure/clojurescript "0.0-2120"]
[cloact "0.0.1"]] [cloact "0.0.2-SNAPSHOT"]]
:plugins [[lein-cljsbuild "1.0.0"]] :plugins [[lein-cljsbuild "1.0.0"]]
:hooks [leiningen.cljsbuild] :hooks [leiningen.cljsbuild]
:profiles {:prod {:cljsbuild :profiles {:prod {:cljsbuild

View File

@ -1,8 +1,8 @@
(defproject todomvc-cloact "0.0.1" (defproject todomvc-cloact "0.0.2-SNAPSHOT"
:dependencies [[org.clojure/clojurescript "0.0-2120"] :dependencies [[org.clojure/clojurescript "0.0-2120"]
[cloact "0.0.1"]] [cloact "0.0.2-SNAPSHOT"]]
:plugins [[lein-cljsbuild "1.0.0"]] :plugins [[lein-cljsbuild "1.0.0"]]
:hooks [leiningen.cljsbuild] :hooks [leiningen.cljsbuild]
:profiles {:prod {:cljsbuild :profiles {:prod {:cljsbuild

View File

@ -22,7 +22,7 @@
nil)})]))) nil)})])))
(def todo-input (with-meta todo-input-render (def todo-input (with-meta todo-input-render
{:component-did-mount #(.focus (:dom-node %))})) {:component-did-mount #(.focus (cloact/dom-node %))}))
(defn todo-item [{:keys [todo on-toggle on-save on-destroy]} this] (defn todo-item [{:keys [todo on-toggle on-save on-destroy]} this]
(dbg "Rendering item") (dbg "Rendering item")

View File

@ -1,6 +1,6 @@
(defproject cloact "0.0.1" (defproject cloact "0.0.2-SNAPSHOT"
:dependencies [[org.clojure/clojurescript "0.0-2120"]] :dependencies [[org.clojure/clojurescript "0.0-2120"]]
:plugins [[lein-cljsbuild "1.0.1"]] :plugins [[lein-cljsbuild "1.0.1"]]
:hooks [leiningen.cljsbuild] :hooks [leiningen.cljsbuild]

View File

@ -9,31 +9,52 @@
(def React tmpl/React) (def React tmpl/React)
(defn create-class [body] ;; (defn as-component [comp]
(comp/create-class body)) ;; (tmpl/as-component comp))
(defn as-component [comp]
(tmpl/as-component comp))
(defn render-component (defn render-component
([comp container] ([comp container]
(render-component comp container nil)) (render-component comp container nil))
([comp container callback] ([comp container callback]
(.renderComponent React (as-component comp) container callback))) (.renderComponent React (tmpl/as-component comp) container callback)))
(defn unmount-component-at-node [container] (defn unmount-component-at-node [container]
(.unmountComponentAtNode React container)) (.unmountComponentAtNode React container))
(defn render-component-to-string [component callback] (defn render-component-to-string [component callback]
(.renderComponentToString React (as-component component) callback)) (.renderComponentToString React (tmpl/as-component component) callback))
(defn set-props [C props] (defn create-class [body]
(comp/set-props C props)) (comp/create-class body))
(defn replace-props [C props]
(comp/replace-props C props))
(defn merge-props [defaults props]
(defn set-props [comp props]
(comp/set-props comp props))
(defn replace-props [comp props]
(comp/replace-props comp props))
(defn props [comp]
(comp/get-props comp))
(defn children [comp]
(comp/get-children comp))
(defn dom-node [comp]
(.getDOMNode comp))
(defn refs [comp]
(.-refs comp))
(defn merge-props
"Utility function that merges two maps, handling :class and :style
specially, like React's transferPropsTo."
[defaults props]
(util/merge-props defaults props)) (util/merge-props defaults props))

View File

@ -14,8 +14,8 @@
(def -ToExtend (js-obj)) (def -ToExtend (js-obj))
(set! (.-prototype -ToExtend) CloactMixin) (set! (.-prototype -ToExtend) CloactMixin)
(declare get-props) ;; (declare get-props)
(declare get-children) ;; (declare get-children)
(extend-type -ToExtend (extend-type -ToExtend
IEquiv IEquiv
@ -39,17 +39,6 @@
(-add-watch [C key f] (assert false "Component isn't really watchable")) (-add-watch [C key f] (assert false "Component isn't really watchable"))
(-remove-watch [C key] (assert false "Component isn't really watchable")) (-remove-watch [C key] (assert false "Component isn't really watchable"))
ILookup
(-lookup [C key]
(-lookup C key nil))
(-lookup [C key not-found]
(case key
:props (get-props C)
:children (get-children C)
:dom-node (.getDOMNode C)
:refs (.-refs C)
not-found))
IHash IHash
(-hash [C] (goog/getUid C))) (-hash [C] (goog/getUid C)))
@ -103,7 +92,7 @@
(defn- do-render [C f] (defn- do-render [C f]
(set! (.-isRenderContext ratom/*ratom-context*) true) (set! (.-isRenderContext ratom/*ratom-context*) true)
(let [res (f (cljs-props C) C @C) (let [res (f (cljs-props C) C)
conv (if (vector? res) conv (if (vector? res)
(tmpl/as-component res) (tmpl/as-component res)
(if (fn? res) (if (fn? res)