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

View File

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

View File

@ -80,12 +80,6 @@
(swap! C assoc :foo "there")
(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")
(is (found-in #"hi you" div))))))