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
Hello! I need some help. How can i connect to postgresql from clojurescript? Basic operations such as create, read update and delete
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.
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) ))
doseq does not returns anything, it is for side effects... use map or for
You are awesome. Thanks for the hint.
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)
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))
I think the idomatic way of accessing JS props is via goog.object
, like goog.object/get
and goog.object/getValueByKeys
see https://lwhorton.github.io/2018/10/20/clojurescript-interop-with-javascript.html and http://clojurescriptmadeeasy.com/blog/js-interop-property-access.html
(TLDR for reasoning is that Closure compiler might mangle the property names if there is no externs provided)
With autoinferencing you don't really need goog.object/get
- you can just use regular interop.
.-target.value
is technically incorrect but it works and is likely to work forever.
There's also (.. event -target -value)
.
That's pretty much it. I haven't seen any widely discussed alternative.
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.
Ok, thanks! I will tentatively continue in this way for now then.
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)
(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...)
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.
Curious, what kind of desktop application would you push for? JavaFx?
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)
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.
@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
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/
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.
@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.
@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.
I think these are official docs: https://cljs.github.io/api/syntax/#dot > The following are also supported…
And here for the (..
macro:
https://cljs.github.io/api/cljs.core/#DOTDOT
Thanks @timothysdean!!!
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?
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.
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?
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/
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?
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)
?
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
In my first project sometimes i did run backend with (-main) in repl, it worked. But then i havent frontend part
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.
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.
ok thank you