clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-10-25T04:20:09.253600Z

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?

2020-10-25T04:20:48.254200Z

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

2020-10-25T04:39:03.254900Z

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

2020-10-25T04:39:13.255200Z

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

2020-10-25T05:57:46.256200Z

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

(defmacro
  ^{: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])}
  def-event-db
  [& args]
  (def-event-db* &env args))

2020-10-25T05:59:29.258100Z

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.

2020-10-25T05:59:48.258700Z

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

danieroux 2020-10-25T19:56:55.260500Z

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: https://github.com/danieroux/create-context-repro/blob/main/src/create_context_repro/core.cljs#L13

2020-10-25T21:01:59.263800Z

I'm trying to load a clojurescript file from an ajax request using XMLHttpRequest, following this snippet: https://stackoverflow.com/questions/18126406/how-can-i-get-the-progress-of-a-downloading-script (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.

2020-10-25T21:02:44.264800Z

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

2020-10-25T21:05:42.265100Z

Here is a repo with the problem: https://github.com/LeifAndersen/ajax-reagent

2020-10-25T21:06:20.265800Z

Running lein figwheel shows it.

2020-10-25T21:07:25.267100Z

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.

p-himik 2020-10-26T07:58:00.273600Z

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.

p-himik 2020-10-25T21:07:30.267200Z

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

p-himik 2020-10-25T21:08:05.267400Z

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

p-himik 2020-10-25T21:08:15.267600Z

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

p-himik 2020-10-25T21:30:57.268Z

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

p-himik 2020-10-25T21:33:13.268200Z

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

2020-10-25T21:38:22.268400Z

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?

2020-10-25T21:39:23.268600Z

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

2020-10-25T21:39:35.268800Z

err :target :bundle + webpack.

p-himik 2020-10-25T21:41:25.269Z

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.

p-himik 2020-10-25T21:42:32.269200Z

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

2020-10-25T21:54:24.269400Z

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

danieroux 2020-10-25T22:12:30.269600Z

Thanks @p-himik! That works for me, on the standard ClojureScript compiler too

👍 2