clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Oliver George 2020-10-22T02:10:19.186300Z

Sounds like something I hit. Some notes on this question about workarounds... https://ask.clojure.org/index.php/9602/recommended-webpack-config-for-clojurescript-bundle-target

Александр Стоянов 2020-10-22T02:15:11.187600Z

Hello! I need some help. How can i connect to postgresql from clojurescript? Basic operations such as create, read update and delete

kozmicluis 2020-10-22T03:23:20.190Z

clojurescript compiles to javascript; and as you know, JS can run on both the browser and servers/computers using the v8 engine. But, if you are using cljs for the frontend web, then there's no way you can directly connect postgres (or any other database) with browser clojurescript (only with nodejs clojurescript). You must have a server that you make http requests to and it should handle all the CRUD operations. If you're referring to cljs for nodejs, then you can use the "pg" npm package directly from clojurescript.

Sophie 2020-10-22T07:58:31.195200Z

Hi everyone I'm trying to program a simple spa with hiccup and cljs but I'm totally stuck now. I'm working with a nested map and I'm not able to show the vals on a webpage. Is there anyone with an idea whats going wrong?

(def liste4 {:rooms {:kueche {:name "Kueche" :m2 "1"}
                     :wohnzimmer {:name "Wohnzimmer" :m2 "2"}
                     :bad {:name "Badezimmer" :m2 ""}
                      }})

(defn inputPage [rNames rSizes]
  [:div {:id "inputLine"}
   [:p rNames ": " rSizes "m2" ]])

(doseq [[k v] (get-in liste4 [:rooms])] (inputPage (v :name) (v :m2)))
Thanks to gon I finally got the solution.
(for [ [%1 %2] (get-in liste4 [:rooms])]
       (inputPage (%2 :name) (%2 :m2) ))

✅ 1
gon 2020-10-22T08:14:01.196100Z

doseq does not returns anything, it is for side effects... use map or for

Sophie 2020-10-22T08:59:21.196600Z

You are awesome. Thanks for the hint.

AJ Jaro 2020-10-22T13:03:00.209600Z

I am pretty sure there is a document that describes the preferred CLJS syntax for JS Interop. Where is the JS interop syntax documented for CLJS related to things like these examples? Ex:

(-> event .-target .value)
or maybe another way
(.-target.value event)

greensponge 2020-10-22T13:03:24.209700Z

Hello everyone, I have a best practices question regarding CSS: I'm playing around with a re-frame template that uses shadow-cljs and seem to have successfully gotten a JS library called ag-grid-react imported to display a table. What is the best way to handle the related CSS files when importing libraries in this way? I ended up running node-sass on the .scss files I wanted in node_modules and put the converted CSS files into resources/public/css and referenced them in index.html. Is there a better way? Some other process or framework I should be using? For reference, so you know my starting point, I've npm installed the needed libraries and done this before using the component/adapter later:

(require: 
  ["ag-grid-react" :as ag-grid :refer (AgGridReact)]
  [reagent.core :as r])

(def ag-adapter (r/adapt-react-class AgGridReact))

victorb 2020-10-22T13:07:17.209900Z

I think the idomatic way of accessing JS props is via goog.object, like goog.object/get and goog.object/getValueByKeys

victorb 2020-10-22T13:08:46.210400Z

(TLDR for reasoning is that Closure compiler might mangle the property names if there is no externs provided)

p-himik 2020-10-22T13:30:06.213200Z

With autoinferencing you don't really need goog.object/get - you can just use regular interop.

p-himik 2020-10-22T13:30:36.213400Z

.-target.value is technically incorrect but it works and is likely to work forever. There's also (.. event -target -value).

p-himik 2020-10-22T13:32:31.213600Z

That's pretty much it. I haven't seen any widely discussed alternative.

greensponge 2020-10-22T14:06:48.221Z

Another question: Say, hypothetically, you were going to build a medium to large in complexity front-end SPA and you were evaluating using CLJS over all the alternatives. Would you pick shadow-cljs or figwheel, or some kind of hybrid (or something else)? Would it matter much if you later changed your mind? I, that is to say ehm, you, would largely be working alone or with one to two teammates. The context is that this would be an internal enterprise application, and you would have to maintain it until your untimely demise or until you no longer worked for company X.

greensponge 2020-10-22T14:07:26.221100Z

Ok, thanks! I will tentatively continue in this way for now then.

zilti 2020-10-22T14:09:59.222Z

I'd pick shadow-cljs, it makes it much easier to use npm packages for the frontend if needed (and when building an SPA, chances are you will need to do so, at least that was my experience when using Fulcro)

👍 1
✔️ 1
➕ 1
zilti 2020-10-22T14:10:56.222600Z

(Though for an internal application especially, I'd do my best to convince them to not make it a web app, but we know how that one goes these days...)

greensponge 2020-10-22T14:16:52.225Z

Thanks @zilti, I hear your point about not making it a web app, though as you said, and based on how the application is going to be accessed (and some other factors), I have little say in this matter.

isak 2020-10-22T14:52:18.225700Z

Curious, what kind of desktop application would you push for? JavaFx?

zilti 2020-10-22T15:00:12.226Z

Yes, JavaFX, probably with cljfx. Because I pretty much discontinued my wrapper ClojureFX. But for as long as it is so cumbersome to native-compile Clojure, that won't really be an option for mobile yet. (Gluon has a Maven plugin that compiles JavaFX applications cross-platform for Windows, Mac, Linux, iOS, Android, but it uses GraalVM native-compile)

1
isak 2020-10-22T15:37:19.226300Z

We're trying this at work (converting an internal CLJS web thing to be a cljfx desktop app.) Not done yet, but looking promising so far.

AJ Jaro 2020-10-22T15:47:39.226600Z

@p-himik Thanks for the response. Do you know where this interop is documented? I couldn’t find it this morning, but I swore it existed

p-himik 2020-10-22T15:53:30.226800Z

I couldn't find any "official" link, but some resources link to this article: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/

👍 1
greensponge 2020-10-22T17:59:19.227800Z

Hello @isak, may I ask what the reason for the switch was? Was there some particular road-block that was too painful to do with CLJS in the web? My motives for asking is that I am seriously considering using CLJS for my next project at work and I'm trying to gain more insight into its current state.

isak 2020-10-22T18:05:41.228Z

@greensponge Well we went from wanting to manage some metadata in the database to managing it as data files in our source control repository instead. For just changing text files on your developer laptop, a webapp doesn't seem like a natural fit, even though it is possible. So no problem with ClojureScript + re-frame, we're still using that heavily for the non-internal screens.

👍 1
greensponge 2020-10-22T18:42:26.228500Z

@isak I see, yes that makes sense, thank you for taking the time to answer and for the additional encouragement in using ClojureScript + re-frame.

1
2020-10-22T19:04:51.228700Z

I think these are official docs: https://cljs.github.io/api/syntax/#dot > The following are also supported…

2020-10-22T19:16:37.228900Z

And here for the (.. macro: https://cljs.github.io/api/cljs.core/#DOTDOT

👍 1
AJ Jaro 2020-10-22T19:46:29.229200Z

Thanks @timothysdean!!!

Александр Стоянов 2020-10-22T21:05:47.230900Z

Hello! How can i execute command (like 'ls' or 'ps') from clojurescript and get back answer? Or how can i execute function from clj file or whole file?

p-himik 2020-10-22T21:35:19.231Z

Do you execute your CLJS in a browser or on NodeJS? If the former, then you will have to have some kind of a backend because browsers don't have any access to the shell commands. Not sure about your second question. You mean executing a CLJ function from CLJS? If so, same answer - you have to be running some backend server and communicate the command and the result client <-> server.

Александр Стоянов 2020-10-22T21:41:30.231200Z

I created lein re-frame template wtih shadow-cljs and didn't understand how to run backend. I just need to connect postgresql and don't know how to do it in this case. Can you help me please?

p-himik 2020-10-22T21:46:26.231400Z

Don't get me wrong, I'd like to help, but that question is almost like the "how do I write a program?" one. There's a great number of approaches, each with its own pros and cons, and ultimately you're the one that has to choose one. Seems like this tutorial makes the choice for you and guides you along the way, so maybe it'll help you: https://practicalli.github.io/clojure-webapps/

Александр Стоянов 2020-10-22T22:09:44.231700Z

My problem a little bit smaller: i can run frontend (by shadow-cljs) but cannot run backend. I have error like "project/server.clj couldnt locate on classpath". So i enter the "server" ns in repl and run (-main) command and it says something like "unable to resolve symbol". What i can do to run backend in this case?

p-himik 2020-10-22T22:25:01.232Z

But that's exactly what I'm saying. shadow-cljs doesn't have any backend built into it that can run arbitrary code. It's just a build tool that has a convenient web server that just serves static files, that's it. What is the server namespace that you use? Where did you get the idea about "entering the ns" in running (-main)?

Александр Стоянов 2020-10-22T22:42:35.232200Z

It means that i need a second project to run backend or how? What i do: 1. run frontend (lein deps && lein watch) 2. run "lein run" - get an error 3. run "lein repl" 4. go to "server" namespace 5. run (-main) - get an error too

Александр Стоянов 2020-10-22T22:45:53.232500Z

In my first project sometimes i did run backend with (-main) in repl, it worked. But then i havent frontend part

Александр Стоянов 2020-10-22T22:48:21.232700Z

Now i have frontend without backend. I just dont know how to run frontend and backend in one project although i can write clojure-code.

p-himik 2020-10-22T22:49:28.232900Z

I don't understand what the item 4 means. And no, you don't need a second project - your project structure can be any you want. Either way, you should definitely follow that tutorial. Alternatively, try asking in the #beginners channel.

Александр Стоянов 2020-10-22T22:49:57.233100Z

ok thank you