mirror of
https://github.com/status-im/reagent.git
synced 2025-02-03 07:33:24 +00:00
Consider symbols to be "identical"
And test some more obscure should-component-update variants.
This commit is contained in:
parent
702f0c3238
commit
d3407ff664
@ -52,16 +52,20 @@
|
||||
(defn shallow-equal-maps [x y]
|
||||
;; Compare two maps, using keyword-identical? on all values
|
||||
(or (identical? x y)
|
||||
(and (== (count x) (count y))
|
||||
(and (map? x)
|
||||
(map? y)
|
||||
(== (count x) (count y))
|
||||
(reduce-kv (fn [res k v]
|
||||
(let [yv (get y k -not-found)]
|
||||
(if (or (keyword-identical? v yv)
|
||||
;; Allow :style maps and reagent/partial
|
||||
;; and :style maps to be compared properly
|
||||
;; Allow :style maps, symbols
|
||||
;; and reagent/partial
|
||||
;; to be compared properly
|
||||
(and (keyword-identical? k :style)
|
||||
(shallow-equal-maps v yv))
|
||||
(and (identical? (type v) partial-ifn)
|
||||
(= y yv)))
|
||||
(and (or (identical? (type v) partial-ifn)
|
||||
(symbol? v))
|
||||
(= v yv)))
|
||||
res
|
||||
(reduced false))))
|
||||
true x))))
|
||||
|
@ -176,6 +176,51 @@
|
||||
(is (found-in #"this is foobar" div))))
|
||||
(is (= 2 @ran)))))
|
||||
|
||||
(deftest shoud-update-test
|
||||
(when isClient
|
||||
(let [parent-ran (atom 0)
|
||||
child-ran (atom 0)
|
||||
child-props (atom nil)
|
||||
f (fn [])
|
||||
f1 (fn [])
|
||||
child (fn [p]
|
||||
(swap! child-ran inc)
|
||||
[:div (:val p)])
|
||||
parent(fn []
|
||||
(swap! parent-ran inc)
|
||||
[:div "child-foo" [child @child-props]])]
|
||||
(with-mounted-component [parent nil nil]
|
||||
(fn [c div]
|
||||
(rflush)
|
||||
(is (= @child-ran 1))
|
||||
(is (found-in #"child-foo" div))
|
||||
(do (reset! child-props {:style {:display :none}})
|
||||
(rflush))
|
||||
(is (= @child-ran 2))
|
||||
(do (reset! child-props {:style {:display :none}})
|
||||
(rflush))
|
||||
(is (= @child-ran 2) "keyw is equal")
|
||||
(do (reset! child-props {:class :foo}) (rflush))
|
||||
(is (= @child-ran 3))
|
||||
(do (reset! child-props {:class :foo}) (rflush))
|
||||
(is (= @child-ran 3))
|
||||
(do (reset! child-props {:class 'foo}) (rflush))
|
||||
(is (= @child-ran 4) "symbols are different from keyw")
|
||||
(do (reset! child-props {:class 'foo}) (rflush))
|
||||
(is (= @child-ran 4) "symbols are equal")
|
||||
(do (reset! child-props {:style {:color 'red}}) (rflush))
|
||||
(is (= @child-ran 5))
|
||||
(do (reset! child-props {:on-change (reagent/partial f)})
|
||||
(rflush))
|
||||
(is (= @child-ran 6))
|
||||
(do (reset! child-props {:on-change (reagent/partial f)})
|
||||
(rflush))
|
||||
(is (= @child-ran 6))
|
||||
(do (reset! child-props {:on-change (reagent/partial f1)})
|
||||
(rflush))
|
||||
(is (= @child-ran 7)))))))
|
||||
|
||||
|
||||
(defn as-string [comp]
|
||||
(reagent/render-component-to-string comp))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user