Fork me on GitHub
#clojurescript
<
2020-01-05
>
mauricio.szabo04:01:55

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...

p-himik07:01:35

How would you change the defn macro?

mauricio.szabo11:01:35

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...

mauricio.szabo11:01:46

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

p-himik11:01:07

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

p-himik12:01:38

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.

darwin12:01:37

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

mauricio.szabo12:01:05

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

victorb11:01:44

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?

p-himik11:01:26

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