From 035dd8bb502c534353453ec881a50fd400f78df7 Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Sat, 28 Mar 2020 22:42:29 +0200 Subject: [PATCH] Move shallow-obj-to-map to utils ns --- src/reagent/impl/component.cljs | 15 ++------------- src/reagent/impl/util.cljs | 14 +++++++++++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 915e2ad..421a3ee 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -11,17 +11,6 @@ ;;; Argv access -(defn shallow-obj-to-map [o] - (let [ks (js-keys o) - len (alength ks)] - (loop [m {} - i 0] - (if (< i len) - (let [k (aget ks i)] - (recur (assoc m (keyword k) (gobj/get o k)) - (inc i))) - m)))) - (defn extract-props [v] (let [p (nth v 1 nil)] (if (map? p) p))) @@ -35,7 +24,7 @@ (defn props-argv [^js/React.Component c p] (if-some [a (.-argv p)] a - [(.-constructor c) (shallow-obj-to-map p)])) + [(.-constructor c) (util/shallow-obj-to-map p)])) (defn get-argv [^js/React.Component c] (props-argv c (.-props c))) @@ -44,7 +33,7 @@ (let [p (.-props c)] (if-some [v (.-argv p)] (extract-props v) - (shallow-obj-to-map p)))) + (util/shallow-obj-to-map p)))) (defn get-children [^js/React.Component c] (let [p (.-props c)] diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index e1e63c5..a3061fb 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -1,5 +1,6 @@ (ns reagent.impl.util - (:require [clojure.string :as string])) + (:require [clojure.string :as string] + [goog.object :as gobj])) (def is-client (and (exists? js/window) (-> (.-document js/window) nil? not))) @@ -186,6 +187,17 @@ (.forceUpdate comp)) (.forceUpdate comp))) +(defn shallow-obj-to-map [o] + (let [ks (js-keys o) + len (alength ks)] + (loop [m {} + i 0] + (if (< i len) + (let [k (aget ks i)] + (recur (assoc m (keyword k) (gobj/get o k)) + (inc i))) + m)))) + ;; React key (defn try-get-react-key [x]