From eb359b301d12e32ce14ed7138677cbe3fc2aa018 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Tue, 6 Oct 2015 10:40:11 +0200 Subject: [PATCH] More property access to component.cljs --- src/reagent/core.cljs | 20 ++++++++++---------- src/reagent/impl/component.cljs | 24 ++++++++++++++++++++++++ src/reagent/impl/util.cljs | 22 ---------------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/reagent/core.cljs b/src/reagent/core.cljs index 7b5927f..158a069 100644 --- a/src/reagent/core.cljs +++ b/src/reagent/core.cljs @@ -136,21 +136,21 @@ Everything is optional, except either :reagent-render or :render. (defn state-atom "Returns an atom containing a components state." [this] - (assert (util/reagent-component? this)) + (assert (comp/reagent-component? this)) (comp/state-atom this)) (defn state "Returns the state of a component, as set with replace-state or set-state. Equivalent to (deref (r/state-atom this))" [this] - (assert (util/reagent-component? this)) + (assert (comp/reagent-component? this)) (deref (state-atom this))) (defn replace-state "Set state of a component. Equivalent to (reset! (state-atom this) new-state)" [this new-state] - (assert (util/reagent-component? this)) + (assert (comp/reagent-component? this)) (assert (or (nil? new-state) (map? new-state))) (reset! (state-atom this) new-state)) @@ -158,7 +158,7 @@ Equivalent to (reset! (state-atom this) new-state)" "Merge component state with new-state. Equivalent to (swap! (state-atom this) merge new-state)" [this new-state] - (assert (util/reagent-component? this)) + (assert (comp/reagent-component? this)) (assert (or (nil? new-state) (map? new-state))) (swap! (state-atom this) merge new-state)) @@ -176,20 +176,20 @@ Equivalent to (swap! (state-atom this) merge new-state)" (defn props "Returns the props passed to a component." [this] - (assert (util/reagent-component? this)) - (util/get-props this)) + (assert (comp/reagent-component? this)) + (comp/get-props this)) (defn children "Returns the children passed to a component." [this] - (assert (util/reagent-component? this)) - (util/get-children this)) + (assert (comp/reagent-component? this)) + (comp/get-children this)) (defn argv "Returns the entire Hiccup form passed to the component." [this] - (assert (util/reagent-component? this)) - (util/get-argv this)) + (assert (comp/reagent-component? this)) + (comp/get-argv this)) (defn dom-node "Returns the root DOM node of a mounted component." diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 21dd4bf..66c1a10 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -9,6 +9,30 @@ (declare ^:dynamic *non-reactive*) + +(defn extract-props [v] + (let [p (nth v 1 nil)] + (if (map? p) p))) + +(defn extract-children [v] + (let [p (nth v 1 nil) + first-child (if (or (nil? p) (map? p)) 2 1)] + (if (> (count v) first-child) + (subvec v first-child)))) + +(defn get-argv [c] + (.' c :props.argv)) + +(defn get-props [c] + (-> (.' c :props.argv) extract-props)) + +(defn get-children [c] + (-> (.' c :props.argv) extract-children)) + +(defn reagent-component? [c] + (-> (.' c :props.argv) nil? not)) + + ;;; State (defn state-atom [this] diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 3808aa7..ae174d6 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -8,28 +8,6 @@ ;;; Props accessors -(defn extract-props [v] - (let [p (nth v 1 nil)] - (if (map? p) p))) - -(defn extract-children [v] - (let [p (nth v 1 nil) - first-child (if (or (nil? p) (map? p)) 2 1)] - (if (> (count v) first-child) - (subvec v first-child)))) - -(defn get-argv [c] - (.' c :props.argv)) - -(defn get-props [c] - (-> (.' c :props.argv) extract-props)) - -(defn get-children [c] - (-> (.' c :props.argv) extract-children)) - -(defn reagent-component? [c] - (-> (.' c :props.argv) nil? not)) - (defn cached-react-class [c] (.' c :cljsReactClass))