-
-
Save ifesdjeen/c10c4cf6f9e7f9db05ac to your computer and use it in GitHub Desktop.
Defmacro
This file contains 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
(defonce ^:dynamic *widgets* {}) | |
(defmacro defwidget | |
[widget-name &{:keys [selector]}] | |
(let [widget-str-name (str widget-name) | |
opts {:selector selector}] | |
`(alter-var-root (var *widgets*) (fn [w#] (assoc w# ~widget-str-name ~opts))))) | |
(defmacro with-widgets [widgets & body] | |
`(binding [*widgets* ~widgets] | |
~@body)) | |
(with-widgets {} | |
(println *widgets*) ;; => {} | |
(defwidget test-widget :selector [:div]) | |
(println *widgets*) ;; => {} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment