Skip to content

Instantly share code, notes, and snippets.

@dwwoelfel
Created August 1, 2014 06:31
Show Gist options
  • Save dwwoelfel/0cd3fd778ae008270098 to your computer and use it in GitHub Desktop.
Save dwwoelfel/0cd3fd778ae008270098 to your computer and use it in GitHub Desktop.
Hack to get something approximating paint rectangles with React/om. Has very rough edges!
(defmacro html [body]
`(if-not (:render-colors? initial-query-map)
(html/html ~body)
(let [body# ~body]
(try
(let [[tag# & rest#] body#
attrs# (if (map? (first rest#))
(first rest#)
{})
rest# (if (map? (first rest#))
(rest rest#)
rest#)]
(html/html (vec (concat [tag# (assoc-in attrs# [:style :border] (str "5px solid rgb("
(rand-int 255)
","
(rand-int 255)
","
(rand-int 255)
")"))]
rest#))))
(catch :default e#
(html/html body#))))))
@dwwoelfel
Copy link
Author

Example of it in action, showing how much extra rendering to the virtual dom we were doing: http://g.recordit.co/bTVTRWEwtZ.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment