Fork me on GitHub
#clojurescript
<
2020-12-28
>
Yehonathan Sharvit04:12:54

Is it possible to write a defalias macro for ClojureScript? defalias should defines an alias for a var, preserving its metadata. I found various implementations for defalias for Clojure but they don’t work as expected in ClojureScript. See for instance https://github.com/ptaoussanis/encore/issues/53 I opened on taoenssso.encore

thheller09:12:38

it is possible to write a macro like that but the impl is incorrect since it works off clojure vars which will not exist for regular CLJS code

thheller09:12:21

and strictly speaking vars don't exist in CLJS runtime so the result will always be different from CLJ

thheller09:12:30

technically the macro would need to grab the analyzer data and replicate it

Yehonathan Sharvit16:12:56

What do you mean by “vars don’t exist in CLJS runtime”?

thheller23:12:43

CLJS doesn't have reified vars at runtime. they only exist in the analyzer data when compiling.

thheller23:12:00

so any kind of var-related coding won't work in CLJS

thheller23:12:24

or rather only a very small subset since its all based on macros getting the data out of the analyzer data

Yehonathan Sharvit06:12:53

What’s the difference between a reified var and a var?

thheller09:12:06

I don't know if I can explain this properly. In CLJ a var is an actual instance of clojure.lang.Var. It can hold a value/thing and have metadata and so on. Its an actual object. In CLJS it is not. In CLJS you just have the thing. var and so on just hide that fact to make it look more like CLJ but it is not.

Yehonathan Sharvit10:12:55

I found this article by @U050B88UR from Dec 2014: https://swannodette.github.io/2014/12/17/whats-in-a-var/ But I still don’t get what is a reified var

macrobartfast08:12:44

sorta offtopic for cljs, forgive me… I’m running a cljs frontend and a clj backend separately… any tips for how to allow my frontend to hit my backend and avoid CORS issues while locally developing?

macrobartfast08:12:06

I always much around trying to figure that out for far too long.

p-himik08:12:12

If you work with a single domain you shouldn't hit CORS issues at all. Either you make requests to some other domains or your backend is misconfigured. Has nothing to do with CLJS or CLJ.

macrobartfast09:12:30

well, my backend serves json endpoints at 8890, and my frontend serves the site at 3000, and the browser doesn’t like that.

macrobartfast09:12:43

it wants it all from the same domain and port.

macrobartfast09:12:59

as far as I can tell, anyway.

macrobartfast09:12:30

and I can’t get both sites to work with the same port, of course.

macrobartfast09:12:00

I mean, both the back-end and front-end server won’t be able to use the same port.

macrobartfast09:12:10

I used to do a full stack thing but restarting the repl is just too big an amount of time for a full stack situation.

thheller09:12:40

just have your backend serve the files directly. there is no need for the 3000 server if you already run a server anyways

3
macrobartfast21:12:37

gotcha… so, for being able to continually build the front end, would you just symlink the compiled site into something the backend can dish up, or?

p-himik21:12:11

Frankly, I don't understand the question. I just both serve the static files and process any API requests with a single web server. Code reloading is done via websockets automatically if you use shadow-cljs. It's 0 configuration setup.

macrobartfast22:12:40

Ah, I understand the confusion… it’s just that I tend to make old style REST endpoints connected to a DB, and that becomes easier to just build as a separate project from the server that provides the site itself that gets data from those endpoints (because of inevitable server/repl restarts in my case)…

macrobartfast22:12:17

and I’ve been doing reagent/re-frame type sites which are involved in their own right, so those also seem more easily built as their own projects.

macrobartfast22:12:36

but I’m wondering, as always, if I’m doing it all wrong.

macrobartfast22:12:11

that said, I’m learning a full-stack framework that should help put these issues to rest, hopefully.