From bfca4e4d3644c484bceeac513bfa02da7b5731ef Mon Sep 17 00:00:00 2001 From: Anton Chikin Date: Sat, 7 Mar 2020 00:23:30 +0300 Subject: [PATCH 1/2] Fix merge-props without classes --- src/reagent/impl/util.cljs | 4 +++- test/reagent/impl/util_test.cljs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index b3920c6..3f100c8 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -147,7 +147,9 @@ rst))) (defn- merge-class [p1 p2] - (assoc p2 :class (class-names (:class p1) (:class p2)))) + (if-let [names (class-names (:class p1) (:class p2))] + (assoc p2 :class names) + p2)) (defn- merge-style [p1 p2] (let [style (when-let [s1 (:style p1)] diff --git a/test/reagent/impl/util_test.cljs b/test/reagent/impl/util_test.cljs index 3c312bf..01f3499 100644 --- a/test/reagent/impl/util_test.cljs +++ b/test/reagent/impl/util_test.cljs @@ -56,6 +56,11 @@ (util/merge-props {:disabled true :style {:flex 1} :class "foo"} {:disabled false :style {:flex-direction "row"} :class "bar"})))) + (testing "two arguments without classes" + (is (= {:disabled false :style {:flex 1 :flex-direction "row"}} + (util/merge-props {:disabled true :style {:flex 1}} + {:disabled false :style {:flex-direction "row"}})))) + (testing "n arguments" (is (= {:disabled false :checked true From 18cdfe9c2b47cdfc58c89ad5346ff9a4345a86ab Mon Sep 17 00:00:00 2001 From: Anton Chikin Date: Fri, 20 Mar 2020 13:17:44 +0300 Subject: [PATCH 2/2] Allow passing :class nil explicitly --- src/reagent/impl/util.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 3f100c8..af28b93 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -147,8 +147,8 @@ rst))) (defn- merge-class [p1 p2] - (if-let [names (class-names (:class p1) (:class p2))] - (assoc p2 :class names) + (if (or (contains? p1 :class) (contains? p2 :class)) + (assoc p2 :class (class-names (:class p1) (:class p2))) p2)) (defn- merge-style [p1 p2]