Fork me on GitHub

I want to add nice error messages in my cljs macro, and I've come across cljs.analyzer/error with an arglist like ([env msg]) - does anybody know what env is and how I can get it so I can pass it?


I suspect it gives file line/column information, but I'm not sure and haven't found any documentation so far


> Clojure macros provide an implicit argument &env that's a map of the local bindings available at macro-expansion time


From The Joy of Clojure__, I'll see if that works


Question about :arglists for docs. This is my macro:

  ^{:doc "Register re-frame db event and bind it to a symbol. Now instead of
(rf/dispatch [::event arg1 arg2])

you can use function call syntax like this:
(rf/dispatch (event arg1 arg2))

Benefits: jump-to-def and arglists work nicely.
    :arglists '([event-sym doc-string? [handler-params] [interceptors?] handler-body])}
  [& args]
  (def-event-db* &env args))


I took the meta map from the defn source, however when I start typing (def-event-db ,,,) the arglist documentation that shows up is just ([& args]) instead of what's in the :arglists metadata.


Is there something more that I have to do to get the proper docstring associated with a macro?


This line, returns true under :none - but false under :advanced. I need help figuring it out: (def has-provider (some? (.-Provider (react/createContext "hmm")))) This is my smallest repro:


If you're using shadow-cljs, just add ^js in front of (react/createContext "hmm").


The issue is due to name mangling during advanced optimizations. Provider in your code becomes something else. ^js tells the optimizer to skip it.


Or something like that. :) I'm not an expert there.


Thanks @U2FRKM4TW! That works for me, on the standard ClojureScript compiler too

👍 6

I'm trying to load a clojurescript file from an ajax request using XMLHttpRequest, following this snippet: (rather than putting a script tag directly in my html). However, it seems like doing this causes clojurescript to erase the entire DOM. As such reagent fails at (.getElementById js/document "app"). I don't see this behavior if I insert a script tag with the resource directly.


Does anyone have any idea why clojurescript might be doing this? I can also upload a small project with this behavior if that helps.


Running lein figwheel shows it.


Oh, and for context, the reason I'm trying to do this is I have a fairly large (~ 7 MB) js file for my actual application, show I would like to show a 'loading bar' for the resource download, otherwise I'd just put the script tag directly in the html, which does work.


Seems to be an issue with having document.write() being called from within document.documentElement.appendChild(). Same for document.body.appendChild().


As a widely supported alternative to manually loading a document, you can try code splitting. Shadow-cljs supports it, maybe figwheel does as well.


So, I ultimately want something that can be put on something like github pages, I'm only using figwheel because it was reagent's default test environment. How hard would it to switch to shadow-cljs?


(I am using :target :bundle in my actual application for npm dependencies if that's a problem.)


err :target :bundle + webpack.


No idea about github pages or :target :bundle, let alone webpack, sorry. But FWIW for me switching to shadow-cljs was quite painless. Had to do some reading, sure (it has a great user's guide), but it was all a smooth ride.


thheller, the author of shadow-cljs, is very active in #shadow-cljs - perhaps he can give some tips if you get stuck.


Okay, I'll give it a look, thanks.


@U2FRKM4TW actually looks to be unrelated to fighweel, like the error persists even when I run the compiled JS from an entirely different server.


Its because if write is called after a page is loaded the document gets erased.


Which....seems to indicate that as long as the cojurescript compiler uses write it might not be possible, at least not without reconstructing the whole document within clojurescript itself.


Either way though, this seems like an interesting enough question on its own I'm going to ask it in the main thread. Thanks again for your feedback.


write can definitely be called after a page is loaded. If called properly, it will just replace the contents of body, but in your initial code it was replacing the whole html. At least, that's how it worked for me. CLJS should not use write with modules created by code splitting, so that might still be an option.