Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Run with `cljs *.clj`
(defn div [x])
(defn generate-component [comp-name params param-values & body]
(println "inside" (pr-str comp-name) (pr-str params) (pr-str body))
`(merge {}
{:args (list ~@param-values),
:name ~(keyword comp-name),
:render (fn [~@params]
(defn ~(symbol (str "call-" comp-name)) [~'%cursor] ~@body))}))
(defmacro defcomp [comp-name params & body]
(println "comp" (pr-str comp-name) (pr-str params) (pr-str body))
`(defmacro ~comp-name [~@params]
(generate-component '~comp-name '~params [~@params] '~@body)))
(println (macroexpand-1 (generate-component 'comp-a '[a] '(div {}))))
(println)
(println (macroexpand-1 '(defcomp comp-a [a] (div {}))))
(defcomp comp-a [a] (div {}))
(println)
(println (macroexpand-1 '(comp-a 2)))
(println)
(println (comp-a 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment