clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2020-09-29T03:28:36.136400Z

what’s the closest equivalent to extend? https://clojuredocs.org/clojure.core/extend seems like https://cljs.github.io/api/cljs.core/extend-type?

theeternalpulse 2020-09-29T04:06:16.138500Z

For devcards, is the best way to organize it to put a folder in the classpath (say src/dev) and mimic the folder structure of he namespaces under test. I have them currently in a src/dev classpath under "<my app name>/devcards.cljs. how do you all do you do it?

murtaza52 2020-09-29T10:25:29.143900Z

there is a very silly error I am getting which doesnt make sense. I am retrieving data from the server using the ajaxlibrary. the server sends the body as application/json, using ring-json-response handler. after retrieving the data I am logging it using (.log js/console (type body)) -> function String (). when I log body I get [[0 0] [1 2 ][2 3]]. So it seems the client received a string. now when I try to (read-string body) I get this error in the console Uncaught TypeError: cljs.core.read_string is undefined Why is clojure.core/read-string not available ? any help will be appreciated, stuck on this one

thheller 2020-09-29T10:30:12.144200Z

@murtaza52 its called cljs.reader/read-string

murtaza52 2020-09-29T10:31:41.144700Z

@thheller thanks, have tried that too, similar error Uncaught TypeError: cljs.reader is undefined

thheller 2020-09-29T10:32:25.145400Z

you need to require and refer or alias it in your ns (:require [cljs.reader :refer (read-string)]) then (read-string foo)

kennytilton 2020-09-29T10:45:35.150100Z

Does any remember why I am using goog.dom/createDom to generate dom instead of *document.createElement()`* ? I just burnt a few hours trying to figure out why a datalist was not working, turns out the list attribute on the input was being silently discarded. Had to do a setAttribute to jam it in. Now I am tempted to switch my whole UI framework off goog.dom. Does it have some advantage i am forgetting?

thheller 2020-09-29T10:55:38.151200Z

@hiskennyness the goog.dom stuff does some compatibility stuff for older browsers and fixes some related quirks. probably safe to use regular dom interop nowadays unless you need to support really old browsers

murtaza52 2020-09-29T11:13:49.151900Z

@thheller thanks, that worked. but shouldnt fns from clojure.core be available by default ?

thheller 2020-09-29T11:14:11.152200Z

its not part of core in cljs. not everything from clojure is available by design.

kennytilton 2020-09-29T11:59:14.155Z

Thx, @thheller! That sounds like why I used goog.dom. But time moves on, so I’ll bet on browsers catching up and lose the dependency. 🙏

Test This 2020-09-29T12:20:34.158100Z

Hi All, I am new to clojure, and definitely plan to use it on the backend. I love svelte on the frontend. It is really good. But I have heard people talk about how much they like clojurescript also. I will appreciate if you can comment on the following: (1) Do you need to first learn react before using reframe/reagent? Surprisingly, I could not find this information. (2) If you have experience with Svelte, would you say that you still prefer Clojurescript. Thank you.

Test This 2020-10-01T00:43:45.199200Z

@hiskennyness Thank you. The things are you saying is one of the big reasons I got interested in Clojurescript. That is what prompted my question. However, if one has to learn react before one can learn Reagent/re-frame, then it makes it a little less attractive. I tried React a long time ago, but gave up because I found Vue to be much easier to learn. Same with Elm and Svelte. They were easier and fun. Even though I am really enjoying Svelte, I would have liked to learn clojurescript with reframe etc for the multiple benefits that few of you have mentioned. However, I cannot get myself to learn React so that I can use Clojurescript.

kennytilton 2020-10-01T01:39:49.199400Z

I have def heard great things about Vue and Elm. Have not looked at Svelte. Anyway, in case I misled you @curiouslearn, you do not have to learn React to learn either re-frame or pure reagent. (re-frame wraps reagent.) Both cljs frameworks hide React, tho I gather you can drill down into React if you have to. I myself found reagent more comfortable because it works like my own Matrix system, but re-frame is hugely popular. Hoplon/javelin is very cool and I think does not involve react. I see Fulcro getting a lot of callouts, as well. I have a fairly https://kennytilton.github.io/whoishiring/ originally done in JS that has been ported to both https://github.com/kennytilton/rehiring and https://github.com/kennytilton/hiringagent. Maybe surf those and see which you want to try?

Test This 2020-10-01T21:08:27.251200Z

@hiskennyness Thank you for these links. Look forward to exploring these. You did not mislead me; that was the impression I got from another post. But I appreciate the clarification because that makes clojurescript much more attractive.

👍 1
restenb 2020-09-29T12:26:50.159700Z

@curiouslearn 1) I would say no, not really. I first started with no React experience (as I basically inherited a re-frame app at work). Still, you'll want to dig into how React works over time to fill in the gaps.

restenb 2020-09-29T12:28:01.161Z

@curiouslearn 2) not familiar with Svelte, but there's definitely scale advantages to using the same language front/backend, not to mention it's easier to mentally process how to implement features from start to finish

Test This 2020-09-29T12:29:58.163200Z

Thank you.

restenb 2020-09-29T12:30:08.163500Z

in my apps I have designed "shared" systems of data processing that both backend and frontend use on the same data, for example

restenb 2020-09-29T12:30:36.164200Z

that are basically the same clojure functions compiled to both targets

victorb 2020-09-29T12:31:49.164600Z

1. as reagent is just a wrapper around react, it's good (but not mandatory) to understand how react works overall before jumping into reagent. Re-frame is a bit similar to redux, so understanding of redux would help grokking re-frame. 2. Have a bit experience with Svelte. It's very different from ClojureScript. Mostly using ClojureScript because it's Clojure that transpiles to JS. Svelte is HTML+JS+CSS while ClojureScript development is mostly just using Clojure data structures for everything that then transpiles to HTML+JS+CSS. Biggest win for me is being able to move between backend/frontend code without having to consider what language/environment I'm in, as most things work the same. Also, would never use anything but Clojure/Script today, unless it can give me a proper repl connected to my state in backend/frontend

victorb 2020-09-29T12:32:23.164800Z

the REPL really spoils you, I'm having a hard time writing anything else but Clojure now, as it's such a frustrating experience not having a REPL aware of application state

Test This 2020-09-29T12:38:40.165600Z

> that are basically the same clojure functions compiled to both targets That is definitely a great advantage.

Test This 2020-09-29T14:01:02.166100Z

@victorbjelkholm429 Thank you. This is very helpful. Any pointers to videos/posts that explain the very basics of how to make REPL aware of the application state. Thank you.

victorb 2020-09-29T14:02:49.166300Z

Best starting resource I've found: https://www.youtube.com/watch?v=j-kj2qwJa_E @bhauman goes through why and how you can use repl to speed up development

victorb 2020-09-29T14:03:36.166600Z

He's using figwheel in that example, lots of people are using shadow-cljs nowadays as well, but not sure about any videos with shadow-cljs that are as easy to understand without much knowledge since before

Test This 2020-09-29T14:27:16.166900Z

Thank you @victorbjelkholm429. I look forward to seeing it.

kennytilton 2020-09-29T16:45:14.168300Z

I think one of the big wins of Reagent/re-frame is not having to deal with the madness of ReactJS. One of the huge wins of CLJS is that it is done. ES still seems to be emerging from the sea. It is a lot better but why mess with the evolution when we have apps to write? 🤷

kennytilton 2020-09-29T17:49:44.170800Z

Pardon a nooby Q, but I have been away. I hear great things about shadow cljs. I am doing great with figwheel:main, loving the hot loading and spectacular error diagnostics. What would be the elevator pitch for switching to shadow? Thx! 🙏

schmee 2020-09-29T17:50:57.172100Z

is there a way to use a single NPM package (mapbox-gl) with figwheel-main, without setting up an entire JS toolchain? can the package be included “manually” somehow?

shivekkhurana 2020-09-29T17:53:33.172300Z

For me, the selling point was first class integration with NPM. You can literally yarn add any-package and :require it in CLJS code. Error diagnostics and hot reloading are at par with Figwheel. I didn't feel any difference when I switched. CLJS recently released support for NPM packages, you can read Shadow' author's views on his blog: https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html

shivekkhurana 2020-09-29T17:54:53.172700Z

You see the message just below yours, asking how to integrate mapbox-gl , things like this are a no-brainer with Shadow.

➕ 1
kennytilton 2020-09-29T18:08:57.174800Z

Ugh, I have PTSD with Node. But I lack seamless package integration. I’ll check it out. Thx!

👍 1
shivekkhurana 2020-09-29T18:12:14.175100Z

Node is too strong to beat by force or resistance, but you can hide in the Shadow.

fossifoo 2020-09-29T18:20:52.177400Z

not sure whether to post here or in #core-async : is there a sane way to run things in async chans in a browser? it seems like any amount of work I do in an async chan will freeze up the render thread since it seems to handle up to 32/1024 scheduled tasks in one batch.

fossifoo 2020-09-29T18:21:52.178700Z

only way forward I see is to do the minimum amount of work in those chans and try to move off to a worker as fast as possible or possibly to split work into smaller chunks

Niclas 2020-09-29T18:27:21.179400Z

Is it possible to list all vars in a ns at runtime, without using macros like ns-publics?

schmee 2020-09-29T18:32:40.179600Z

I just set this up with figwheel-main and it was a no-brainer there as well, but I had to drag in npm and webpack which I wanted to avoid for the same reasons as @hiskennyness

👍 1
schmee 2020-09-29T22:21:46.180900Z

what’s difference between (mapboxgl/Map. #js {:container "app"})) and (.Map mapboxgl #js {:container "app"}))?

victorb 2020-09-30T07:32:55.182200Z

They're the same.

victorb 2020-09-30T07:33:12.182600Z

If you wanna check the JS output of some cljs quickly you can use http://app.klipse.tech/

schmee 2020-09-30T18:59:09.189500Z

that is… very strange 😐

schmee 2020-09-30T18:59:35.189700Z

I spent many hours yesterday trying to fix a bug and in the end it turned out that the first form caused the bug while the second one didn’t

schmee 2020-09-30T18:59:45.189900Z

but you’re saying they are equivalent?

orestis 2020-10-03T12:41:16.257600Z

They’re not - the first one uses “new” while the second calls a function. Notice the dot at the end.

victorb 2020-10-03T12:46:20.257800Z

Hah, true! Good catch @orestis If you (@schmee) would have put the same code you put here, in app.klipse.tech you would have discovered the difference! I missed the following . when I first read it

schmee 2020-10-03T13:51:25.258200Z

ahh, there it is, thank you @orestis @victorbjelkholm429! :thumbsup:

schmee 2020-10-03T13:51:38.258400Z

follow up question: is it a JS thing to be able to call a constructor as a function or something like that?

schmee 2020-10-03T13:52:02.258600Z

I would have suspected this sooner if I got some sort of “function not defined” error in the second case, but instead I got a completely unrelated error

orestis 2020-10-03T14:15:15.260100Z

Yeh it’s a JS thing and can be very confusing in plain JS too. Using new gives different semantics to “this” IIRC.

👍 1