Skip to content

Commit 998b632

Browse files
committed
Cleanup defc code
1 parent 8b1007a commit 998b632

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/reagent/impl/template.cljs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
(or (named? x)
2929
(string? x)))
3030

31+
(defn ^boolean reagent-fn-component? [^clj x]
32+
(.-reagent-component x))
33+
3134
(defn ^boolean valid-tag? [^clj x]
3235
(or (hiccup-tag? x)
33-
(.-reagent-component x)
36+
(reagent-fn-component? x)
3437
(ifn? x)
3538
(instance? NativeWrapper x)))
3639

@@ -171,7 +174,12 @@
171174
(set! (.-key jsprops) key))
172175
(react/createElement c jsprops)))
173176

174-
(defn reag-element-2 [tag v]
177+
(defn defc-element
178+
"Tag is a React function component already wrapped
179+
with Reagent function component implementation. This function just
180+
needs to wrap the Hiccup element children into the React element
181+
properties and set up the optional React key if set."
182+
[tag v]
175183
(let [jsprops #js {}]
176184
(set! (.-argv jsprops) (subvec v 1))
177185
(when-some [key (util/react-key-from-vec v)]
@@ -300,8 +308,8 @@
300308
:f> (function-element (nth v 1 nil) v 2 compiler)
301309
:<> (fragment-element v compiler)
302310
(cond
303-
(.-reagent-component tag)
304-
(reag-element-2 tag v)
311+
(reagent-fn-component? tag)
312+
(defc-element tag v)
305313

306314
(hiccup-tag? tag)
307315
(hiccup-element v compiler)

0 commit comments

Comments
 (0)