mirror of
https://github.com/status-im/reagent.git
synced 2025-01-28 04:36:21 +00:00
Make equality checking more consistent
This commit is contained in:
parent
41962bbe18
commit
c1f2f59bbc
@ -131,29 +131,31 @@
|
|||||||
|
|
||||||
(def -not-found (js-obj))
|
(def -not-found (js-obj))
|
||||||
|
|
||||||
|
(defn identical-ish? [x y]
|
||||||
|
(or (keyword-identical? x y)
|
||||||
|
(and (or (symbol? x)
|
||||||
|
(identical? (type x) partial-ifn))
|
||||||
|
(= x y))))
|
||||||
|
|
||||||
(defn shallow-equal-maps [x y]
|
(defn shallow-equal-maps [x y]
|
||||||
;; Compare two maps, using keyword-identical? on all values
|
;; Compare two maps, using identical-ish? on all values
|
||||||
(or (identical? x y)
|
(or (identical? x y)
|
||||||
(and (map? x)
|
(and (map? x)
|
||||||
(map? y)
|
(map? y)
|
||||||
(== (count x) (count y))
|
(== (count x) (count y))
|
||||||
(reduce-kv (fn [res k v]
|
(reduce-kv (fn [res k v]
|
||||||
(let [yv (get y k -not-found)]
|
(let [yv (get y k -not-found)]
|
||||||
(if (or (keyword-identical? v yv)
|
(if (or (identical? v yv)
|
||||||
;; Allow :style maps, symbols
|
(identical-ish? v yv)
|
||||||
;; and reagent/partial
|
;; Handle :style maps specially
|
||||||
;; to be compared properly
|
|
||||||
(and (keyword-identical? k :style)
|
(and (keyword-identical? k :style)
|
||||||
(shallow-equal-maps v yv))
|
(shallow-equal-maps v yv)))
|
||||||
(and (or (identical? (type v) partial-ifn)
|
|
||||||
(symbol? v))
|
|
||||||
(= v yv)))
|
|
||||||
res
|
res
|
||||||
(reduced false))))
|
(reduced false))))
|
||||||
true x))))
|
true x))))
|
||||||
|
|
||||||
(defn equal-args [v1 v2]
|
(defn equal-args [v1 v2]
|
||||||
;; Compare two vectors using identical?
|
;; Compare two vectors using identical-ish?
|
||||||
(assert (vector? v1))
|
(assert (vector? v1))
|
||||||
(assert (vector? v2))
|
(assert (vector? v2))
|
||||||
(or (identical? v1 v2)
|
(or (identical? v1 v2)
|
||||||
@ -161,6 +163,7 @@
|
|||||||
(reduce-kv (fn [res k v]
|
(reduce-kv (fn [res k v]
|
||||||
(let [v' (v2 k)]
|
(let [v' (v2 k)]
|
||||||
(if (or (identical? v v')
|
(if (or (identical? v v')
|
||||||
|
(identical-ish? v v')
|
||||||
(and (== 1 k)
|
(and (== 1 k)
|
||||||
(shallow-equal-maps v v')))
|
(shallow-equal-maps v v')))
|
||||||
res
|
res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user