Fork me on GitHub
#clojurescript
<
2020-09-29
>
theeternalpulse04:09:16

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?

murtaza5210:09:29

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

thheller10:09:12

@murtaza52 its called cljs.reader/read-string

murtaza5210:09:41

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

thheller10:09:25

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

kennytilton10:09:35

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?

thheller10:09:38

@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

murtaza5211:09:49

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

thheller11:09:11

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

kennytilton11:09:14

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 This12:09:34

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.

victorb12:09:49

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

victorb12:09:23

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 This14:09:02

@UEJ5FMR6K 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.

victorb14:09:49

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

victorb14:09:36

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 This14:09:16

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

kennytilton16:09:14

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? 🤷

Test This00:10:45

@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.

kennytilton01:10:49

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 This21:10:27

@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.

👍 3
restenb12:09:50

@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.

restenb12:09:01

@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

restenb12:09:08

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

restenb12:09:36

that are basically the same clojure functions compiled to both targets

Test This12:09:40

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

kennytilton17:09:44

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! 🙏

shivekkhurana17:09:33

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

shivekkhurana17:09:53

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

3
kennytilton18:09:57

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

👍 3
shivekkhurana18:09:14

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

schmee18:09:40

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

👍 3
schmee17:09:57

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?

fossifoo18:09:52

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.

fossifoo18:09:52

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

Niclas18:09:21

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

schmee22:09:46

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

victorb07:09:55

They're the same.

victorb07:09:12

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

schmee18:09:09

that is… very strange 😐

schmee18:09:35

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

schmee18:09:45

but you’re saying they are equivalent?

orestis12:10:16

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

victorb12:10:20

Hah, true! Good catch @U7PBP4UVA If you (@U3L6TFEJF) 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

schmee13:10:25

ahh, there it is, thank you @U7PBP4UVA @UEJ5FMR6K! :thumbsup:

schmee13:10:38

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

schmee13:10:02

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

orestis14:10:15

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

👍 3