This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-25
Channels
- # announcements (1)
- # architecture (3)
- # beginners (31)
- # calva (61)
- # cider (1)
- # clojure (43)
- # clojure-dev (17)
- # clojure-europe (85)
- # clojure-uk (8)
- # clojurescript (31)
- # cryogen (2)
- # cursive (7)
- # data-science (12)
- # datalog (1)
- # datomic (4)
- # defnpodcast (1)
- # figwheel-main (11)
- # fulcro (32)
- # hoplon (1)
- # leiningen (1)
- # malli (47)
- # pedestal (1)
- # rdf (2)
- # re-frame (11)
- # reagent (4)
- # reitit (7)
- # shadow-cljs (22)
- # vrac (8)
- # xtdb (2)
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
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))
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: https://github.com/danieroux/create-context-repro/blob/main/src/create_context_repro/core.cljs#L13
The issue is due to name mangling during advanced optimizations. Provider
in your code becomes something else. ^js
tells the optimizer to skip it.
Thanks @U2FRKM4TW! That works for me, on the standard ClojureScript compiler too
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.
Does anyone have any idea why clojurescript might be doing this? I can also upload a small project with this behavior if that helps.
Here is a repo with the problem: https://github.com/LeifAndersen/ajax-reagent
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.)
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.
@U2FRKM4TW Hmm..it actually looks to be unrelated to fighweel, like the error persists even when I run the compiled JS from an entirely different server.
@U2FRKM4TW GOT IT...kinda: https://javascript.info/modifying-document
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.