Compare state with identical? in shouldComponentUpdate

And fix render bug
This commit is contained in:
Dan Holmsand 2013-12-17 12:26:23 +01:00
parent 08d082e365
commit 89e7392269
3 changed files with 7 additions and 13 deletions

View File

@ -103,7 +103,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) f @C) (let [res (f (cljs-props C) C @C)
conv (if (vector? res) conv (if (vector? res)
(tmpl/as-component res) (tmpl/as-component res)
(if (fn? res) (if (fn? res)
@ -141,12 +141,12 @@
:shouldComponentUpdate :shouldComponentUpdate
(fn [C nextprops nextstate] (fn [C nextprops nextstate]
(assert (nil? f) "shouldComponentUpdate is not yet supported") (assert (nil? f) "shouldComponentUpdate is not yet supported")
(assert (vector? (-> C .-props .-cljsArgs))) (let [a1 (args-of C)
(let [a1 (-> C .-props .-cljsArgs)
a2 (-> nextprops .-cljsArgs) a2 (-> nextprops .-cljsArgs)
ostate (.-cljsOldState C) ostate (.-cljsOldState C)
eq (and (tmpl/equal-args a1 a2) eq (and (identical? ostate nextstate)
(= ostate nextstate))] (tmpl/equal-args a1 a2))]
(assert (vector? a1))
(set! (.-cljsOldState C) nextstate) (set! (.-cljsOldState C) nextstate)
(not eq))) (not eq)))

View File

@ -83,8 +83,8 @@
true true
(let [props1 (nth v1 1)] (let [props1 (nth v1 1)]
(if (or (nil? props1) (map? props1)) (if (or (nil? props1) (map? props1))
(and (= props1 (nth v2 1)) (and (identical-parts v1 v2 2)
(identical-parts v1 v2 2)) (= props1 (nth v2 1)))
(identical-parts v1 v2 1))))))) (identical-parts v1 v2 1)))))))
(declare wrapper) (declare wrapper)

View File

@ -80,12 +80,6 @@
(swap! C assoc :foo "there") (swap! C assoc :foo "there")
(is (found-in #"hi there" div)) (is (found-in #"hi there" div))
(let [runs @tests-run]
;; should not be rendered
(swap! C assoc :foo "there")
(is (found-in #"hi there" div))
(is (= runs @tests-run)))
(swap! C assoc :foo "you") (swap! C assoc :foo "you")
(is (found-in #"hi you" div)))))) (is (found-in #"hi you" div))))))