clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Yehonathan Sharvit 2020-12-28T04:43:54.491500Z

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

thheller 2020-12-28T09:23:38.493300Z

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

thheller 2020-12-28T09:24:21.493500Z

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

thheller 2020-12-28T09:26:30.494900Z

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

Yehonathan Sharvit 2020-12-28T16:15:56.496600Z

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

thheller 2020-12-28T23:03:43.498400Z

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

thheller 2020-12-28T23:04:00.498600Z

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

thheller 2020-12-28T23:04:24.498800Z

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

Yehonathan Sharvit 2020-12-29T06:11:53.499500Z

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

thheller 2020-12-29T09:14:06.499700Z

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 Sharvit 2020-12-29T10:11:55Z

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

macrobartfast 2020-12-28T08:07:44.492500Z

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?

macrobartfast 2020-12-28T08:08:06.492900Z

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

p-himik 2020-12-28T08:47:12.493100Z

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.

macrobartfast 2020-12-28T09:24:30.493800Z

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

macrobartfast 2020-12-28T09:24:43.494Z

it wants it all from the same domain and port.

macrobartfast 2020-12-28T09:24:59.494300Z

as far as I can tell, anyway.

macrobartfast 2020-12-28T09:25:30.494500Z

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

macrobartfast 2020-12-28T09:26:00.494700Z

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

macrobartfast 2020-12-28T09:27:10.495100Z

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.

thheller 2020-12-28T09:27:40.495300Z

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

➕ 1
macrobartfast 2020-12-28T21:07:37.497Z

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-himik 2020-12-28T21:14:11.497200Z

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.

macrobartfast 2020-12-28T22:15:40.497600Z

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)…

macrobartfast 2020-12-28T22:16:17.497800Z

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.

macrobartfast 2020-12-28T22:16:36.498Z

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

macrobartfast 2020-12-28T22:17:11.498200Z

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