clojurescript

Quentin Le Guennec 2024-11-18T15:11:25.514529Z

Can I read js/document into a clojure structure ?

thheller 2024-11-18T15:13:14.505529Z

no. well I mean if you write a function for it yes, by default no.

Quentin Le Guennec 2024-11-18T15:19:56.197219Z

I see, thanks

Macroz 2024-11-18T15:47:46.255609Z

Maybe something like https://github.com/mfikes/cljs-bean

Macroz 2024-11-18T15:48:02.470489Z

Why would you want to do that?

Quentin Le Guennec 2024-11-18T15:49:34.270639Z

I’m consuming an api that returns a xml body

Macroz 2024-11-18T15:53:50.828599Z

I guess I would do one of: • use JS-interop directly (it's not too bad) • capture some small bit of information from the XML-string (works for simple small case) • parse the XML (if I need to do it in CLJS and I need flexibility) (and by parsing I mean convert into hiccup or hickory depending on the need) • parse in CLJ and do the heavy lifting there (if I have CLJ)

Quentin Le Guennec 2024-11-18T15:57:47.400929Z

yeah I think I’m just gonna try using xml2js and then convert it with clj->js. The data is not very large so it should be sufficient.

Macroz 2024-11-18T15:59:08.975449Z

tubax seems to be the library that internally uses sax-js too

Macroz 2024-11-18T15:59:36.773389Z

Depending on what you have already, avoiding more dependencies should be good :)

Quentin Le Guennec 2024-11-18T15:59:46.401129Z

good point.

Slackbot 2024-11-18T16:19:07.309709Z

This message was deleted.

p-himik 2024-11-18T16:28:56.350149Z

Seems like a problem with highlight.js that's not related to CLJS at all.

Jan Šuráň 2024-11-18T16:37:05.379889Z

Oh well, if you want a CLJS problem... 😂

Jan Šuráň 2024-11-18T16:37:47.287269Z

I'm trying to fitgure out, why I sometimes cannot change the :require header, because shadow-cljs -reload fails...

Jan Šuráň 2024-11-18T16:38:41.855359Z

Anyways, where could I talk about JS libraries?

p-himik 2024-11-18T16:42:43.625039Z

Regarding the shadow-cljs issue - usually in #shadow-cljs. Regarding JS libraries - if you have an issue with a specific library, then I'd look at where the authors of the library ask you to report the issues. Most often, just GitHub issues, sometimes other places.

Macroz 2024-11-18T16:43:42.183969Z

Besides asking there ☝️ , make a clean rebuild, and if that fails then you could try a small repro because that's usually when you find out that it was something in the project instead.

Macroz 2024-11-18T16:44:57.560359Z

I don't recall any problem with CLJS highlight.js so maybe it's a newer version thing or some misconfiguration?

Jan Šuráň 2024-11-18T16:58:45.017369Z

@macroz well, clean rebuild helped a few times already, but after some time, the problem appears again 😞

Macroz 2024-11-18T17:02:37.626219Z

Do you use an external packaging tool or just Shadow-CLJS?

Jan Šuráň 2024-11-18T17:13:20.603419Z

I use package.json instead of :npm-deps which should work the same, right?

Macroz 2024-11-18T17:14:04.408999Z

I meant in Shadow-CLJS

Macroz 2024-11-18T17:14:25.444789Z

But yes, I use package.json too

Macroz 2024-11-18T17:14:42.293349Z

Thinking about if you for example use webpack in the mix too, or something.

Jan Šuráň 2024-11-18T17:15:00.716119Z

Oh, yeah, I use shadow-cljs + npm

Macroz 2024-11-18T17:15:22.667519Z

And sometimes when you reload your app you get that error?

Jan Šuráň 2024-11-18T17:15:27.805409Z

Yes

Jan Šuráň 2024-11-18T17:16:55.055189Z

Actually, it has been some time since I tried adding another language extension

Jan Šuráň 2024-11-18T17:18:14.208869Z

But anyways, I tried adding Nim, because I wanted to test something and I got this message. However, after I reloaded the browser, it actually used Nim's rules to automatically highlight the Nim source. So it might just be a bug when I try to reload the namespace at runtime, idk...

Macroz 2024-11-18T17:19:26.277009Z

Could it be that it does not load the extension in time?

Macroz 2024-11-18T17:19:51.232369Z

Sounds like a race condition / timing issue if it happens sometimes.

Macroz 2024-11-18T17:20:30.201929Z

So e.g. the registerLanguage or so happens "too late"

Jan Šuráň 2024-11-18T17:21:07.674649Z

Yeah, I also feel like that might be it, but it's impossible to debug, because the stacktrace is literally a bunch of garbage

Jan Šuráň 2024-11-18T17:21:21.853599Z

registerLanguage has nothing to do with it

Jan Šuráň 2024-11-18T17:21:59.300139Z

even if I import a language submodule without calling registerLanguage, it still fails

Macroz 2024-11-18T17:22:28.593489Z

Well if it is this problem, then it is not going to be in the stacktrace because of design. highlight.js seems to have a global registry inside and whether a thing is loaded there or not can cause the problem.

Jan Šuráň 2024-11-18T17:22:49.517549Z

But it's interesting that a while ago, it failed on literally every language that hasn't "already been there" (that I haven't been using for some time), but after reload, I tried different languages and all of them worked fine.

Jan Šuráň 2024-11-18T17:24:13.839849Z

I think this isn't handled by highlight.js , because I just :require the submodule, like everything else, without calling anything else from highlight.js

Macroz 2024-11-18T17:24:35.333789Z

Yeah true

p-himik 2024-11-18T17:26:06.604989Z

Hot code reloading is not magic that resolves everything for you, unfortunately. It might very well that that highlight.js with a custom configuration is not amenable to hot code reload and you have to guard that custom config or some other parts that use it with stuff like defonce. And if something should be reset/reconfigured after a code reload, there are hooks for that. The same thing you might use for re-rendering the page with Reagent, for example.

Macroz 2024-11-18T17:26:39.327689Z

So I require ["highlight.js/lib/core" :default hljs] and ["highlight.js/lib/languages/clojure" :as hljs-clojure] And in my start function (.registerLanguage hljs "clojure" hljs-clojure)

Macroz 2024-11-18T17:28:33.064579Z

I do not recollect any code reload problems, but this was some year ago

Macroz 2024-11-18T17:29:09.027219Z

Also in stop function I do (.unregisterLanguage hljs "clojure")

Macroz 2024-11-18T17:30:43.446099Z

In shadow-cljs.edn

:devtools
   {:before-load 
    :after-load }

Jan Šuráň 2024-11-18T17:30:48.283649Z

Well, I don't necessarily need to load new languages at runtime, but you know, when something goes wrong, you really want to know, why, and whether you should ignore it or not 😄

Macroz 2024-11-18T17:31:01.635749Z

I think you should not be getting that error 🙂

Jan Šuráň 2024-11-18T17:31:35.186729Z

Hmm, I didn't even know you could use :before-load for this

Macroz 2024-11-18T17:32:25.296339Z

For this project I don't seem to be using the metadata version of it.

Macroz 2024-11-18T17:33:00.200809Z

Starting highlight.js is part of the app startup in my case so it makes sense to be in there.

Jan Šuráň 2024-11-18T17:35:14.597749Z

It would be nice if I could wait for this error to appear again and try solving it using this, to see, whether it helped, but if that reloads the entire build, I wouldn't really know, whether it wouldn't get fixed just because of the build reload