Created
February 18, 2024 09:37
-
-
Save PEZ/357df3589dc49e83e49da77cb8943723 to your computer and use it in GitHub Desktop.
A workaround to make default linting resolve `dumdom.core/defcomponent` without complaints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-dumdom.macros | |
(:require [dumdom.core :as dumdom])) | |
(defn- extract-docstr | |
[[docstr? & forms]] | |
(if (string? docstr?) | |
[docstr? forms] | |
["" (cons docstr? forms)])) | |
(defn- extract-opts | |
([[argvec ?opts & forms]] | |
(assert (vector? argvec)) | |
(if (map? ?opts) | |
[?opts (cons argvec forms)] | |
[{} (list* argvec ?opts forms)]))) | |
(defmacro defcomponent | |
"A workaround to make default linting resolve `defcomponent` without complaints. | |
Instead of this: | |
(defcomponent Widget | |
\"A Widget\" | |
:on-mount #(...) | |
:on-render #(...) | |
[value constant-value] | |
(some-child-components)) | |
We can write this: | |
(defcomponent Widget | |
[value constant-value] | |
{:name \"A Widget\" | |
:on-mount #(...) | |
:on-render #(...)} | |
(some-child-components))" | |
[name & forms] | |
(let [[docstr forms] (extract-docstr forms) | |
[options forms] (extract-opts forms) | |
[argvec & body] forms | |
options (merge {:name (str (:name (:ns &env)) "/" name)} options)] | |
`(def ~name ~docstr (dumdom.core/component (fn ~argvec ~@body) ~options)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not the author of this macro. Don't know who is, actually.
NB: Before using this macro, consider importing the clj-kondo linting config that ships with the dumdom library.