Fork me on GitHub
#clojurescript
<
2024-02-01
>
Patrick Brown13:02:07

Two general cljs/js questions? 1. Why exactly did the cljs community gravitate towards Express? 2. Sitefox, Macchiato, and ____? What are the mature cljs server projects? Do they all use Express? 3. Is this a ring thing? If so why don’t the cljs servers implement the spec? 4. Is there a good story for getting a reagent app to SSR on Cloudflare Workers/Pages

martinklepsch15:02:49

As for 1-3, I think just nobody wrote a ring compliant server for node. For 4, I’d recommend a more minimal React wrapper, although it shouldn’t be impossible with Reagent. What specifically is unclear maybe? Main challenge usually is that components (or even namespaces) require browser APIs and then usually it’ll be more difficult to get SSR to work.

Patrick Brown17:02:06

Appreciate the comeback. I was just trying to get a handle on cljs for server. It’s a strange story. My conclusion after a few hours is that I like sitefox. I don’t have any use for it, but it’s very cool. And squint may create something transcendentally cool for clojure, but for now I’m straight JVM server side.

hifumi12319:02:05

I’ve never seen anyone use express and would love to know how youve reached that conclusion. Macchiato offers a somewhat Ring-compliant adapter to the default http server in Node. No idea about Cloudflare Workers since I dont use that. People tend to prefer JVM Clojure for their web servers (probably due to more libraries available, and probably due to much better performance and tooling for debugging, deployment, etc.)

Chris McCormick20:02:52

1. I can't speak for others but Express is mature and already what I knew on Node, so I chose it for Sitefox. 2. Sitefox is not mature. It says "WIP" (work in progress) because I don't think it's ready for other people to build production code on just yet. I have production code on it myself but that's because it's my own code and I love fixing production bugs at 3am. 😁 facepalm I am working towards removing the "WIP" tag at the moment thanks to ClojuristsTogether funding. 3. I don't use ring and don't know much about it. I wanted to build Sitefox on the JS standard stack. 4. I don't think it would be difficult at all to SSR Reagent forms in Cloudflare workers . Just use Reagent's render-to-static-markup in your worker code and build to a js artifact for deployment. If it's useful you can look at some of the https://github.com/chr15m/sitefox/blob/main/src/sitefox/html.cljs#L74-L96 for doing this (and also for injecting fragments into a static HTML blob). I find the function I use the most is select-apply which is vaguely like enlive in that it lets you make various modifications to the HTML including injecting Reagent before sending it back to the client. Hope this helps and thanks for your interest!

Omer ZAK22:02:41

A clueless newbie question: When you refer to 'ring', what technology do you mean here? Neither Google nor Wikipedia were helpful for me. The word 'ring' has several meanings in every relevant context. My best guess is: Is it the correct guess?

kennytilton02:02:26

I disambiguated by searching google for "clojure ring", @U06BDSLBVC6. Then that ^^ was the first hit. hth!

👍 1
Omer ZAK22:02:33

If I want to generate a ClojureScript project using lein, I need to choose a suitable template for lein new command. I found a list of leiningen templates for ClojureScript in The advice of lein help new was to search for 3rd party templates. However, I saw no easy way to find advice for choosing a template with which to start a simple ClojureScript project. So I am asking here for advice.

p-himik22:02:50

IMO the best way is to simply create what you need by hand. A minimal project is just a single project.clj file (with a bit of boilerplate that's easier to type than to remember the name of a template) and a src directory.

Omer ZAK22:02:30

Your suggestion is good for someone who is experienced in developing in ClojureScript, as you left out the step of finding a suitable boilerplate. I happen to be a beginner, and should have asked in #beginner. My bad :white_frowning_face:

p-himik22:02:08

To a beginner, I'd recommend doing it manually even more so. It's a very valuable learning experience. Plenty of pain in the direction of easy starts, normal development, and hard truths about wrong choices. I'd recommend using tools.deps instead of Leiningen (so, deps.edn instead of project.clj) and shadow-cljs as a CLJS compiler, which has great docs: https://shadow-cljs.github.io/docs/UsersGuide.html There's also a bare-bones shadow-cljs-based project to get you up and running when developing for a browser: https://github.com/shadow-cljs/quickstart-browser If you decide to use it, I'd definitely recommend going through its code while checking everything with the shadow-cljs docs so you know what's going on.

p-himik22:02:46

(You might've guessed that templates are somewhat of a pet peeve of mine. Dictated by poor quality or unmaintained templates, and a lot of vicariously experienced pain with create-react-app which is not too dissimilar to templates).

😂 2
Omer ZAK23:02:25

@U2FRKM4TW, Thanks for the links. In a way, they answer my quest for a ClojureScript quickstart.

hifumi12323:02:32

for a beginner id not recommend either lein or deps.edn. instead, use pure shadow-cljs until you have a reason to use lein or deps.edn

hifumi12323:02:55

that way all you need to do is

npm install shadow-cljs
npx shadow-cljs init
and you're set this assumes you've installed node.js already

p-himik23:02:10

Using deps.edn with shadow-cljs is trivial and immediately enables all the tooling. Not a lot of things support shadow-cljs.edn.

hifumi12323:02:37

there's also templates on npm like npx create-cljs-app (or create-helix-app, or uix starter template, ...) that offer tons of more scaffolding but that requires you to be familiar with tools used in the template

hifumi12323:02:06

@U2FRKM4TW what are these "things"? the only reason id integrate jvm clojure tooling is to make use of e.g. git deps, or integrate cljs into an existing clj project i dont expect beginners to run into these situations, hence prefer a single tool rather than two tools

p-himik23:02:37

IDEs (Cursive and, last time I checked, clojure-lsp), any tools that work with deps.edn (antq, clj-kondo also doesn't support it I think, tools.deps.graph, and so on).

hifumi12323:02:57

VS Code, Emacs, and Vim plugins support shadow-cljs. Cursive is the exception, not the rule. Antq definitely scans shadow-cljs.edn files — I use it all the time. Ditto for clj-kondo (I use this indirectly via clojure-lsp)

hifumi12323:02:26

For a beginner I would definitely recommend VS Code over Cursive (not even personal preference, simply because VS Code is what has the most tutorials and documentation out there. I personally use Emacs). And Calva uses Clojure LSP under the hood, I have used it successfully in projects with only shadow-cljs in them

hifumi12323:02:10

There’s definitely benefits to integrating shadow-cljs with deps or lein, but for a beginner, it’s more likely to present additional cognitive load rather than any immediate, tangible benefit.

p-himik23:02:41

Ah, alright, my knowledge is outdated then. But to make sure that the OP still considers it - integrating shadow-cljs with deps.edn is just specifying all the dependencies in deps.edn and adding :deps true to shadow-cljs.edn. That's it. The only downside is that you have to restart shadow-cljs when changing the set of dependencies.

thheller10:02:25

(that downside always applies, even with shadow-cljs.edn)

p-himik10:02:04

Huh, I was certain that shadow-cljs picked the changes in dependencies in shadow-cljs.edn without restarting the sever. Probably mixed it up with package.json.

thheller10:02:25

yeah its a jvm limitation that you cannot change the classpath after starting. well you can but it has all sorts of issues and I rather not deal with those