diff --git a/src/cloact/impl/template.cljs b/src/cloact/impl/template.cljs index bc2a660..0f6a0c6 100644 --- a/src/cloact/impl/template.cljs +++ b/src/cloact/impl/template.cljs @@ -69,6 +69,7 @@ objprops)))) (defn identical-parts [v1 v2 from] + ;; Compare two vectors, from item with index "from", using identical? (let [end (count v1)] (loop [n from] (if (>= n end) @@ -77,17 +78,35 @@ (recur (inc n)) false))))) +(def -not-found (js-obj)) + +(defn shallow-equal-maps [x y] + ;; Compare two maps, using identical? on all values + (or (identical? x y) + (when (== (count x) (count y)) + (reduce-kv (fn [res k v] + (let [yv (get y k -not-found)] + (if (or (identical? v yv) + ;; hack to allow cloact.core/partial + (and (ifn? v) (= v yv))) + res + (reduced false)))) + true x)))) + (defn equal-args [v1 v2] - (let [c1 (count v1)] - (and (= (nth v1 0) (nth v2 0)) - (identical? c1 (count v2)) - (if (< c1 2) - true - (let [props1 (nth v1 1)] - (if (or (nil? props1) (map? props1)) - (and (identical-parts v1 v2 2) - (= props1 (nth v2 1))) - (identical-parts v1 v2 1))))))) + ;; Compare two "args" vectors, i.e things like [:div {:foo "bar} "baz"], + ;; using identical? on all individual parts. + (or (identical? v1 v2) + (let [c1 (count v1)] + (and (= (nth v1 0) (nth v2 0)) ; may be symbol or fn + (identical? c1 (count v2)) + (if (< c1 2) + true + (let [props1 (nth v1 1)] + (if (or (nil? props1) (map? props1)) + (and (identical-parts v1 v2 2) + (shallow-equal-maps props1 (nth v2 1))) + (identical-parts v1 v2 1)))))))) (declare wrapper)