allow for defvc components to include doc comments and attribute maps

just like reagent components would be able to do when defined with defn
This commit is contained in:
Gered 2016-05-25 13:42:11 -04:00
parent 20be582a1a
commit d5e421de52

View file

@ -11,8 +11,22 @@
components defined with defvc will automatically manage subscribing
and unsubscribing to views as the view signatures passed to any
view-cursor calls change across the lifetime of this component."
[component-name args & body]
`(defn ~component-name []
{:arglists '([component-name doc-string? attr-map? [params*] body])}
[component-name & decl]
(let [attr-map (if (string? (first decl))
{:doc (first decl)}
{})
decl (if (string? (first decl))
(next decl)
decl)
attr-map (if (map? (first decl))
(conj attr-map (first decl))
attr-map)
decl (if (map? (first decl))
(next decl)
decl)
[args & body] decl]
`(defn ~component-name ~attr-map []
(reagent.core/create-class
{:component-will-mount
(fn [this#]
@ -39,4 +53,4 @@
:component-function
(fn ~args
~@body)})))
~@body)}))))