From 41962bbe18329125474aacf4598c9ca12817a2e3 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Tue, 11 Feb 2014 12:41:00 +0100 Subject: [PATCH] Reduce is great. Use it more --- src/reagent/impl/component.cljs | 12 +++++++----- src/reagent/impl/util.cljs | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 69dfe8b..4f4d5a8 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -149,9 +149,10 @@ (def obligatory {:shouldComponentUpdate nil :componentWillUnmount nil}) -(defn camelify-map-keys [m] - (into {} (for [[k v] m] - [(-> k tmpl/dash-to-camel keyword) v]))) +(defn camelify-map-keys [fun-map] + (reduce-kv (fn [m k v] + (assoc m (-> k tmpl/dash-to-camel keyword) v)) + {} fun-map)) (defn add-obligatory [fun-map] (merge obligatory fun-map)) @@ -178,8 +179,9 @@ fmap (-> fun-map (assoc :displayName name') (add-render render-fun))] - (into {} (for [[k v] fmap] - [k (get-wrapper k v name')])))) + (reduce-kv (fn [m k v] + (assoc m k (get-wrapper k v name'))) + {} fmap))) (defn map-to-js [m] (reduce-kv (fn [o k v] diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index d90d834..956f28c 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -154,14 +154,15 @@ (defn equal-args [v1 v2] ;; Compare two vectors using identical? + (assert (vector? v1)) + (assert (vector? v2)) (or (identical? v1 v2) - (let [end (count v1)] - (and (== end (count v2)) - (loop [n 1] - (if (>= n end) - true - (if (or (identical? (v1 n) (v2 n)) - (and (== 1 n) - (shallow-equal-maps (v1 1) (v2 1)))) - (recur (inc n)) - false))))))) + (and (== (count v1) (count v2)) + (reduce-kv (fn [res k v] + (let [v' (v2 k)] + (if (or (identical? v v') + (and (== 1 k) + (shallow-equal-maps v v'))) + res + (reduced false)))) + true v1))))