Fork me on GitHub

Hi there! Is there any way to conditionally decide how to add some code to a ClojureScript macro? I want to add some debugging info to some defn vars, but only on development. I was thinking about using the js/goog.DEBUG var, but I found that on macro expansion time I can't access that var...


How would you change the defn macro?


Writing a macro to write the defn, for example. The thing is, as macros must be written in Clojure, I'm not seeing a way to use some ClojureScript var to conditionally use on my macro...


(I don't even know if it is possible, to be honest)


Ah, so you don't want to replace defn, you want just change the body passed to it conditionally, right?


Also I'm not sure but you could probably still use js/goog.DEBUG, just in CLJS and not during macro expansion. Because of DCE, the branch that couldn't be reached in runtime should be removed.


sure, he could emit js/goog.DEBUG dependent cljs code in his macro


Great, I'll probably go through the js/goog.DEBUG route. I completely forgot that it would be dead-code eliminated 🙂


I'm trying to understand cljs.js/eval a bit better, and trying to figure out if there is a way for me to have some communication between pieces of code that run within eval, and outside. So, I'm trying to setup some onClick handles on a hiccup component that is saved to disk, but later dynamically loaded and evaluated to make the onClick handles actually functions. When these functions are called, I want them to be able to communicate with the surrounding code. Is there any way of accomplishing this? What I've tried so far: • Keep track of compiler state and eval a "shared" function, but it's not the same function anymore, so any references are broken, so it won't work for me • Started looking into using load-analysis-cache! but I'm afraid it would suffer from the same problem as above, would be executed in a new scope Any other ideas that could help me?


Do you really need to have a fully dynamic solution? Why do you need to save hiccup components on disk?