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
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
and strictly speaking vars don't exist in CLJS runtime so the result will always be different from CLJ
technically the macro would need to grab the analyzer data and replicate it
What do you mean by “vars don’t exist in CLJS runtime”?
CLJS doesn't have reified vars at runtime. they only exist in the analyzer data when compiling.
so any kind of var-related coding won't work in CLJS
or rather only a very small subset since its all based on macros getting the data out of the analyzer data
What’s the difference between a reified var and a var?
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.
I found this article by @dnolen 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
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?
I always much around trying to figure that out for far too long.
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.
well, my backend serves json endpoints at 8890, and my frontend serves the site at 3000, and the browser doesn’t like that.
it wants it all from the same domain and port.
as far as I can tell, anyway.
and I can’t get both sites to work with the same port, of course.
I mean, both the back-end and front-end server won’t be able to use the same port.
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.
just have your backend serve the files directly. there is no need for the 3000 server if you already run a server anyways
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?
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.
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)…
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.
but I’m wondering, as always, if I’m doing it all wrong.
that said, I’m learning a full-stack framework that should help put these issues to rest, hopefully.