clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-10-12T02:46:43.397400Z

I got it to work, providing an explicit key depending on the src url fixed it, still not sure why it didn't work without one

2020-10-12T02:51:17.398600Z

Hey all - running into an issue with npm-deps in cljs - everything works fine until I add some npm-deps to my project, at which point reagent's local variable that's supposed to be pointing to react-dom becomes undefined. This is using figwheel

reefersleep 2020-10-12T08:59:01.401Z

I’d take it to #figwheel or #figwheel-main , then 🙂 And alternatively, you could try using shadow-cljs, it seems to be pretty good for npm deps. I believe npm deps are newer to figwheel than to shadow-cljs, but I also think that Bruce is pretty active and motivated in fixing whatever npm deps problem you might be having with figwheel.

2020-10-12T02:53:12.399Z

hmm that's strange, I removed :npm-deps from the compiler options and the problem is still here... maybe this is a compiler cache issue

2020-10-12T02:54:42.399200Z

well this is strange... I nuked the target directory entirely and the problem is still here

2020-10-12T02:54:55.399400Z

so much state 😭

2020-10-12T02:56:39.399600Z

what on earth... I removed node_modules too and it's still happening

2020-10-12T03:00:59.399800Z

Now I'm getting ReferenceError: $jscomp is not defined

2020-10-12T03:01:05.400Z

this is so brittle...

2020-10-12T03:04:13.400200Z

now every time I build I get Unable to resolve symbol: import in this context 1993 without a filename

2020-10-12T03:23:41.400400Z

finally got everything to work by completely busting the cache and removing node_modules, but now every time I add it back I get the same error... it seems figwheel+reagent+react-dom really don't work well together at all, which is kind of baffling to me

victorb 2020-10-12T08:36:07.400600Z

Seems like maybe you're changing the src after it already been rendered (hitting this: https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element "Dynamically modifying a `source` element and its attribute when the element is already inserted in a `video` or `audio` element will have no effect."), while if you add the :key to it, it rerenders the entire element and reinserts it with the new src set, rendering properly.

Chris McCormick 2020-10-12T08:55:03.400800Z

one gotcha i've run into with reloading js code is the const keyword is not reload friendly as it will throw an error if you try to rebind something with the same name.

reefersleep 2020-10-12T08:59:01.401Z

I’d take it to #figwheel or #figwheel-main , then 🙂 And alternatively, you could try using shadow-cljs, it seems to be pretty good for npm deps. I believe npm deps are newer to figwheel than to shadow-cljs, but I also think that Bruce is pretty active and motivated in fixing whatever npm deps problem you might be having with figwheel.

Rico Meinl 2020-10-12T09:09:16.403Z

Hey everyone! Cljs beginner here. Does anyone have a solid and simple setup for clojurescript to create and export to Javascript code which I can then host as a gist

Day Bobby 2020-10-12T09:13:20.403100Z

clojurescript exports to unreadable javascript code so I don't think you can use it for a gist

Day Bobby 2020-10-12T09:13:36.403300Z

but I'm also a beginner maybe someone else can give you a better answer

Day Bobby 2020-10-12T09:15:13.404200Z

anybody using clojurescript for backend node development? If so, what are you using to interface with sql databases?

2020-10-12T09:35:26.404300Z

If you don’t use any optimization, you can see the correlation if you squint a bit, but it won’t really be useful. Why do you want a gist of the generated code?

Rico Meinl 2020-10-12T09:38:19.405800Z

Not necessarily a gist. Just a js file that I can load via <script>. It's for a roamresearch extension

p-himik 2020-10-12T09:39:41.406Z

If your CLJS snippets don't require any dependencies, then you can use http://app.klipse.tech/

Rico Meinl 2020-10-12T09:40:52.406400Z

They do :/

victorb 2020-10-12T09:41:29.406600Z

if you're doing backend development, why not go straight for clojure instead of clojurescript? If you're still using clojurescript for backend (for whatever reason), maybe try using what you're already used to in JS but interop with it in CLJS, should get you up and running quickly

p-himik 2020-10-12T09:42:40.406800Z

Ah, then I'd just follow the shadow-cljs user's guide. :) You should end up with a scaffolding that has just 2-3 files with a few lines in them.

Day Bobby 2020-10-12T09:46:55.407Z

It's a backend for my web crawler. I plan to use puppeteer js for the scraping part because puppeteer doesn't have a java client, now I just need a way to persist the scraped data. In Node land I use typeorm for this kind of stuff buts its tied heavily to typescript, guess I will try to find a light alternative (something more like next.jdbc for node). Thank you!

zilti 2020-10-12T09:50:53.407200Z

There's Etaoin to remote-control browsers from Clojure, I'm using it in production here for a web crawler/scraper.

Day Bobby 2020-10-12T09:55:44.407400Z

Wow I didn't know about it. Thank you! May I ask have you used Puppeteer before, and if so is there any major difference between the two?

victorb 2020-10-12T09:55:48.407600Z

"reloading JS code" is not really the same as "reloading CLJS code", at least in the React Hot Code Reload world, as it's not all code that gets reloaded, either the component itself gets reloaded and reinserted or the entire file gets reevaluated, while in clojure land it's just updating vars with new forms, regardless

victorb 2020-10-12T09:58:13.407800Z

I've used both, for scraping as well 🙂 Etaoin is nice in that it's still using webdriver protocol, so easier to integrate everywhere. Mostly it's just the API itself that differ, as Etaoin is made in traditional clojure fashion (works well with repl workflow) while puppeteer as a traditional JS API (wants to evaluate and rerun the entire file on change). Of course this can be worked around, but no need when a nice API already exists. When using Etaoin for testing I also managed to get all of Chrome, Firefox and Safari to work it and I think puppeteer only works with chrome and firefox (3rd party)

victorb 2020-10-12T09:58:29.408Z

(although, haven't used puppeteer from clojurescript, only vanilla js)

Day Bobby 2020-10-12T10:03:04.408200Z

This is super useful, thank you guys.

2❤️
Chris McCormick 2020-10-12T11:20:47.408700Z

true

2020-10-12T16:15:30.409400Z

I thought so, but another SO issue claimed that setting the src element directly, without an embedded <source> element should fix it. I am however replacing another video element with a srcObject and no src, maybe it doesn't rerender that correctly otherwise? :thinking_face:

victorb 2020-10-12T16:18:16.409600Z

Hm, yeah, setting src on video should update correctly indeed. Strange huh

teodorlu 2020-10-12T18:25:11.412300Z

I want to apply some function (x,y) to each (x,y) value on a 500x500 grid, in order to draw on a <canvas> with decent FPS. Should I consider more efficient storage for the numbers than Clojure vectors? In Clojure, I'd reach for tech.ml.dataset.

p-himik 2020-10-12T18:41:53.412500Z

I would write the simplest implementation that comes to mind, measure its performance, and tweak it till it's sufficient. Hard to say anything in advance, especially without knowing the target PCs' specs and the function.

1👍
isak 2020-10-12T18:48:46.412700Z

^. My backup plan would be a plain javascript array with length 500*500, then just calculate the index based on x and y.

1👍1➕
teodorlu 2020-10-12T18:56:35.413200Z

Thanks for the advice! I like the simple sound of a plain 1d javascript array. Reminds me of https://github.com/mikera/imagez, which uses a 1d java array to store images. That was a pleasure to work with.

1
thom 2020-10-12T19:00:49.414900Z

What kind of functions are you appointing over the data? There are various WebGL backed matrix implementations for JavaScript, even if you’re not using WebGL for rendering.

1👍
teodorlu 2020-10-12T19:04:41.415400Z

Plain math, at least to begin with. Coordinate transformations, colors

Milan Munzar 2020-10-12T19:19:09.421500Z

Hello, it seems that ClojureScript doesn't support BigInt literal N (at least on node). I have found a Jira issue, but it is closed. Is it a known issue? Construction via js/BigInt, works as expected. But operator ** doesn't seem to work. Does anyone manage to work it out? Thx! :)

Justin Chandler 2020-10-12T21:03:16.427500Z

Hey, everyone! Got a small question that's more like a general web dev question rather than specifically ClojureScript. I've written a small app in ClojureScript using a 3D WebGL library that displays a 3D model of a TV and streams an MP4 onto the screen. I can't really figure out what determines whether a link is compatible though. For https://live.gcloud mp4's it streams fine, but for others I can go to the url and download the mp4 but not stream it from my web app. At first I thought it was just that they only allowed downloads, but apparently another javascript player called JWPlayer grabs the same url that only hosts downloads and streams it from the website just fine. What's the difference?

Justin Chandler 2020-10-12T21:45:34.427600Z

Ah never mind, it's not a problem with implementation, it's just CORS authentication. Doesn't even matter for the final web app.

Trung Dinh 2020-10-12T23:25:27.430200Z

hi , I’m trying to replicate react-window example (https://codesandbox.io/s/github/bvaughn/react-window/tree/master/website/sandboxes/fixed-size-list-vertical?file=/index.js) with no luck, can someone please point me how should it be done? my take was

(defn row [index, style]
  [:div {:style style
         :background-color (when (= 1 (mod index 2)) "#F8F8F0")}
   (str "Row" index)])

(defn example []
  [:&gt; FixedSizeList {:height 150
                     :item-count 1000
                     :item-size 35
                     :width 300
                     :border "1px solid black"}
   [row]])

(defn app []
  [:&lt;&gt;
   [example]]

p-himik 2020-10-12T23:40:06.430400Z

According to that example, row is a function that has to return an element. By itself, row is not a component. Try replacing [row] with just row and wrapping the whole body of the row function in (reagent.core/as-element ...).