This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-15
Channels
- # announcements (1)
- # babashka (21)
- # beginners (23)
- # biff (8)
- # boot (1)
- # cider (4)
- # clerk (21)
- # clj-kondo (31)
- # clojure (60)
- # clojure-brasil (5)
- # clojure-europe (20)
- # clojurescript (21)
- # datomic (14)
- # graalvm (10)
- # honeysql (1)
- # hoplon (4)
- # hyperfiddle (42)
- # introduce-yourself (1)
- # leiningen (1)
- # lsp (53)
- # pathom (4)
- # releases (2)
- # scittle (24)
- # shadow-cljs (3)
- # xtdb (4)
Hey folks, good night! I'm writing a backend using Ring, Compojure and Hiccup. I'm able to return the HTML nicely to the browser, but I'd like to use ClojureScript instead of JavaScript to give more life to the pages. I don't want to create a SPA, I'd like to continue using Server Side Rendering. Is there some recommended way to do it? Most of the solutions I found uses frameworks that are no longer supported.
May I ask what you mean by "giving life" to the pages, and why you prefer server-side rendering to an SPA?
You can use shadow-cljs to compile to js, and use browser api to manipulate the dom without any framework.
@UAZ28QUJZ I'd like to just add validations before posting forms for example. Or either some calls to an API to just get an answer and manipulate some parts of the screen, without having to load the entire application upfront in the customer browser. I don't want he downloads the admin part if he is not admin, or downloading parts of the application that he is not suppose to see or know that exists too. I've worked with SPAs using React for the past 5 years and even thinking is awesome separating fully the frontend from the backend, I'd like to create a simpler application without having to completely split them.
@U01SBSXRRH6 I will take a look on those to see if matches my needs! I come back later with more info 😅
You do not need anything, but JQuery works fine and would make you feel like you were holding onto a trellis instead of floating around in mid-air. For example you could post questions to there's probably a JQuery message board. On top of JQuery (which you do not need), you also do not need a ClojureScript wrapper, which for example I remember there was one called jayq that might still work and could be fun for the sake of amusement. But keep in mind you probably nowadays do not need any of that.
You may interested with my Inertia.js Clojure adapter: https://github.com/prestancedesign/inertia-clojure
Here is a complete demo app using it https://github.com/prestancedesign/pingcrm-clojure
It requires only minor changes to the backend to get SPA like app. Fell free to ask if you have some questions.
Hey Michael (sorry the typo, I didn't find on my keyboard how to do it!), looks like exactly what I was looking for! I change my laptop and I'm doing the setup. When I finish it I will try implement and reach you if I need. Thank you for the suggestion!
Michael, it worked! Really cool Inertia, but the @U01SBSXRRH6 suggestion end up working almost exactly the way I expected. The shadow-cljs made possible to create a ClojureScript that was possible to be referenced by a generated file from backend. I had to use as string, but it worked. From the backend the code was a Hiccup template like this:
(defn delete-product [id]
(html
; Other code
[:div.btn-group
[:input.btn.btn-danger.btn-xs
{:type :button
:onclick "gadgetzan.frontend.app.click();"
:value "Delete"}]]]))
In the layout I just had to refer the output from shadow-clj as this:
[:script {:src "/js/app.js"}]
And in the CLJS file just a regular function:
(defn click []
(js/alert "Deleting..."))
I’m been using clojure for tooling and personal projects for a good bit now. I’d now like to start working with clojurescript for some small utilities delivered by web. My general preference here and what I like to do for the kinds of tools I create is stand up pure SPAs with no backend at all, leveraging localstorage and occasionally direct front-end calls to APIs. I’m curious what people think are the main choices for this sort of work, the lighter the better?
Still looking for comments here, however I’m currently looking at Ulx2, which seems like a good candidate.
UIx2 is cool or try hicada if you want to get as close as possible to barebones JSX/React.
re-frame/reagent if you want some kind of framework to get things going and don't want to write a bunch of stuff for state management yourself.
shadow-cljs is the best option to add some javascript libraries/components to your project.
and get yourself familiar with advanced compilation quirks, as sometimes it can bite you unexpectedly if you're not careful.
@U0250GGJGAE Check out https://babashka.org/scittle/ if you want to play around with reagent/re-frame
Helix is probably the lightest react wrapper out there, but it does offer some convenience features for hooks like use-ref
(e.g. being able to deref
instead of having to call (.-current ref)
yourself, and being able to swap!
and reset!
it).
It’s also in the process of getting extra performance improvements by replacing calls to React.createElement to modern JSX calls, which allow React to do optimizations that it otherwise can’t with createElement
Thanks all, very helpful. Looking into everything mentioned here.