Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Created November 20, 2012 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifesdjeen/c10c4cf6f9e7f9db05ac to your computer and use it in GitHub Desktop.
Save ifesdjeen/c10c4cf6f9e7f9db05ac to your computer and use it in GitHub Desktop.
Defmacro
(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