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:
parent
20be582a1a
commit
d5e421de52
|
@ -11,32 +11,46 @@
|
||||||
components defined with defvc will automatically manage subscribing
|
components defined with defvc will automatically manage subscribing
|
||||||
and unsubscribing to views as the view signatures passed to any
|
and unsubscribing to views as the view signatures passed to any
|
||||||
view-cursor calls change across the lifetime of this component."
|
view-cursor calls change across the lifetime of this component."
|
||||||
[component-name args & body]
|
{:arglists '([component-name doc-string? attr-map? [params*] body])}
|
||||||
`(defn ~component-name []
|
[component-name & decl]
|
||||||
(reagent.core/create-class
|
(let [attr-map (if (string? (first decl))
|
||||||
{:component-will-mount
|
{:doc (first decl)}
|
||||||
(fn [this#]
|
{})
|
||||||
(reagent-data-views.client.component/prepare-for-render! this#))
|
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#]
|
||||||
|
(reagent-data-views.client.component/prepare-for-render! this#))
|
||||||
|
|
||||||
:component-did-mount
|
:component-did-mount
|
||||||
(fn [this#]
|
(fn [this#]
|
||||||
; invoked immediately after the initial render has occurred.
|
; invoked immediately after the initial render has occurred.
|
||||||
; we do this here because component-did-mount does not get called
|
; we do this here because component-did-mount does not get called
|
||||||
; after the initial render, but will be after all subsequent renders.
|
; after the initial render, but will be after all subsequent renders.
|
||||||
(reagent-data-views.client.component/update-subscriptions! this#))
|
(reagent-data-views.client.component/update-subscriptions! this#))
|
||||||
|
|
||||||
:component-will-unmount
|
:component-will-unmount
|
||||||
(fn [this#]
|
(fn [this#]
|
||||||
(reagent-data-views.client.component/unsubscribe-all! this#))
|
(reagent-data-views.client.component/unsubscribe-all! this#))
|
||||||
|
|
||||||
:component-will-receive-props
|
:component-will-receive-props
|
||||||
(fn [this# new-argv#]
|
(fn [this# new-argv#]
|
||||||
(reagent-data-views.client.component/prepare-for-render! this#))
|
(reagent-data-views.client.component/prepare-for-render! this#))
|
||||||
|
|
||||||
:component-did-update
|
:component-did-update
|
||||||
(fn [this# old-argv#]
|
(fn [this# old-argv#]
|
||||||
(reagent-data-views.client.component/update-subscriptions! this#))
|
(reagent-data-views.client.component/update-subscriptions! this#))
|
||||||
|
|
||||||
:component-function
|
:component-function
|
||||||
(fn ~args
|
(fn ~args
|
||||||
~@body)})))
|
~@body)}))))
|
||||||
|
|
Loading…
Reference in a new issue