Fork me on GitHub
#clojurescript
<
2021-04-16
>
macrobartfast02:04:46

I need to add a back end to what I’ve created with create-shadow-cljs-app which has been awesome… I’ve used Luminus and so on in the past but am not attached to anything… I develop locally and will be hosting it all on something like Digital Ocean… I’ve gotten wary of the totally integrated front-and-back end solutions as any hang makes me have to reload it all. Is it possible to develop the front and back ends separately and still connect to the repl’s from Emacs? I always run into CORS confusion doing that while developing locally… any thoughts or quick suggestions of approaches to look at?

djblue05:04:38

My preferred approach is running a shadow-cljs dev server with a custom ring handler for my API. Single nrepl connection for both clj/cljs repl, single http server so no CORS and it starts up fast enough 👌

djblue05:04:57

I think you can also setup shadow-cljs to proxy API requests to another server if you are really sold on two separate processes

djblue05:04:44

https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http lists a variety of ways you could configure the dev server

macrobartfast06:04:09

Cool… this is helpful. I’m not sold on any approach at all… I just am pretty confused probably about what’s actually going on.

macrobartfast06:04:27

How do you create your shadow-cljs apps at the start?

macrobartfast06:04:45

I fell in love with create-shadow-cljs-app.

💯 3
macrobartfast06:04:58

but can easily move on to whatever.

macrobartfast06:04:23

My probably incorrect thinking is that I have to add a ton of stuff in to shadow-cljs to get a back end working along with it… when the truth may not be that at all.

macrobartfast06:04:11

Reading the link you had in your message earlier now.

macrobartfast06:04:48

Holy smokes… it looks like I can do it all in shadow-cljs with a ring handler. I think you just said that, haha. 🙂

💯 3
macrobartfast06:04:29

Demerits to me for not RTFM.

😆 3
djblue06:04:51

I usually just copy a shadow-cljs.edn from project to project 😬

djblue06:04:08

Another benefit with having both in the same process is you can use the shadow-cljs inspector for both clj/cljs

djblue06:04:55

You can access it via http://localhost:9630/ just in case you didn't know 👌

djblue06:04:05

Being able to tap> clojure data into a dedicated ui is a game changer clojure-spin

macrobartfast07:04:13

shadow-cljs inspector… get outta town… one sec…

macrobartfast07:04:00

well I’ll be damned.

macrobartfast07:04:28

I’ve seen that in a framework… I just didn’t realized I had it with any shadow-cljs project.

💯 3
Franco Gasperino17:04:38

Glad i read this thread. The tap & inspect functionality is a great find

💯 3
macrobartfast00:04:08

any thoughts on starting an app with lein new luminus someapp +reagent +shadow-cljs vs create-cljs-app?

macrobartfast00:04:01

it sounds like you might do neither.

djblue02:04:27

Sorry, I haven't used those templates but I do really enjoy reagent 💯

djblue02:04:28

They recently added https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#function-components in the 1.0 release which makes it super easy to leverage react hooks

djblue02:04:14

(def functional-compiler (reagent.core/create-compiler {:function-components true}))
(reagent.dom/render [my-app] div functional-compiler)
It's opt in though to preserve backwards compatibility

macrobartfast03:04:27

what does that enable (I forgot the advantages of React hooks).

djblue03:04:52

I think it mostly just makes it easier to interop with various libraries in the react ecosystem

macrobartfast02:04:39

I’m also excited about a couple frameworks but they still don’t play nicely with my Emacs live dev setup so I’m still going this route for now.

macrobartfast02:04:31

I often use cider-connect-to-clj&cljs in Emacs when a framework type thing launches both… but I guess if I did them separately I’d do them in turn.

macrobartfast02:04:18

I’m not against a combined front-end/back-end situation, btw… I just recall loooong restarts when I bork my recur experimentation. 🙂

djblue05:04:29

Is cider interrupt not able to kill this repl eval?

macrobartfast06:04:37

It doesn’t seem to work… the page gets hung in an endless reload… but I’m probably doing something wrong.

macrobartfast02:04:33

Maybe some approaches reload quickly or work that out another way.

introom15:04:52

I wonder is there any documentation on the type hint ^js here: (.registerComponent ^js (.-AppRegistry rn) “app” #(reagent/reactify-component views/root))

dvingo15:04:04

https://shadow-cljs.github.io/docs/UsersGuide.html#infer-externs this section Type-hint to help externs generation explains it

introom16:04:14

Isn’t that something owned by the cljs compiler and not shadow?

p-himik16:04:48

It is. But it's documented in more than one place.

dvingo17:04:51

Is it documented on the clojurescript site? I didn't see it there

p-himik17:04:31

Stuff like ^js/SomeType is documented. I haven't seen the documentation for ^js specifically there, but it's in the CLJS compiler code.