clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-03-24T00:01:20.235600Z

Thanks, that makes sense.

Max 2021-03-24T00:48:56.240800Z

So, bit of an odd question: I’d like to use https://clojureverse.org/t/best-practices-for-importing-raw-text-files-into-clojurescript-projects/2569 (a macro that uses io and slurp) to inline a big JSON file into a cljs project. The inlining macro part works fine, but I’d also like to parse the file from JSON into clojure data structures/EDN at compile-time. That requires an external dependency, but only for clojure (not clojurescript) and only at compile-time. Is there a way to specify clojure compilation dependencies separately from clojurescript dependencies? A lot of the clojure JSON parsers rely on Java libraries and I suspect things would get mad if I specified them as normal clojurescript dependencies. I’m using shadow-cljs (I think that matters?)

thheller 2021-03-24T08:36:24.244800Z

FWIW you should absolutely avoid inlining larger files into a build this way. the source compiled variant of edn will be much larger than the original edn and bloat your bundle size. ideally load data at runtime instead.

nilern 2021-03-24T08:54:58.245Z

Inlining the JSON string should be fine though?

thheller 2021-03-24T08:59:11.245200Z

totally depends on the size. you don't want to inline 1mb of json. 1kb is fine.

nilern 2021-03-24T09:05:29.245400Z

Depends on the use case also. Browsers have not been mentioned so it might be a toaster.

Max 2021-03-24T22:34:17.260Z

Good to know! In this particular case, I’m trying to create a single-html-file application to ease distribution of an application and I’m not actually serving it over the web, so size isn’t much of a concern. But it’s good to know that EDN compiles larger than the equivalent string. Thanks for the tip!

thheller 2021-03-25T08:35:44.260400Z

yeah it would still be better to just inline the edn string and parse it at runtime

p-himik 2021-03-24T00:53:50.241Z

Things won't get mad. :)

Max 2021-03-24T00:54:29.241200Z

So I just mix it in with my normal clojurescript dependencies and everything will figure itself out?

p-himik 2021-03-24T00:55:18.241400Z

Yep.

p-himik 2021-03-24T00:55:56.241600Z

If something somehow blows up, it would likely deserve a minimal reproducible example shared in #shadow-cljs

1
zackteo 2021-03-24T02:10:58.242800Z

Are there any resources I can look at for how to integrate Clojurescript into a pre-existing JS codebase?

zackteo 2021-03-24T02:56:40.243Z

Specifically it is a React + Reframe codebase

zackteo 2021-03-24T02:59:28.243200Z

Am doing a ClojureScript project for my final year project and will be discussing with my ex-colleague (doing my capstone project with a company I interned at) , how the integration pathway might be like if our work is something they want to integrate back into their js codebase

solf 2021-03-24T03:05:38.243400Z

I don't have any personal experience doing that. If you're not using shadow-cljs, consider using it, and then this link could be useful: https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module

zackteo 2021-03-24T04:00:32.243800Z

Hmmm that seems to work :thinking_face:

zackteo 2021-03-24T04:03:27.244Z

I guess reagent components could be accessed via this too hmmm

zackteo 2021-03-24T09:27:49.246800Z

How do I convert the lein template like lein new reagent myproject from lein-figwheel to figwheel-main ?

zackteo 2021-03-24T09:28:51.248Z

Also, does it make sense to use shadow-cljs as a compilation target and figwheel main as the repl type? I don't really understand where shadow fits into this

thheller 2021-03-24T09:33:55.248500Z

no, you use either shadow-cljs or figwheel. not both. shadow-cljs also provides repl and hot-reload and so on

phoenixjj 2021-03-24T09:36:12.250100Z

@zackteo - It would be easier to create project first then add figwheel-main as described in it's documentation.

phoenixjj 2021-03-24T09:39:08.250800Z

or

lein new figwheel-main myproject -- --reagent

2021-03-24T09:39:15.251Z

Is there a straightforward way to override toString on my records?

2021-03-24T09:40:11.251300Z

I found a message on the google group talking about this, but what is suggested seems to have no effect.

zackteo 2021-03-24T10:11:08.253200Z

Oh :o right. Might something like this be a good starting point then ? https://github.com/lauritzsh/reagent-shadow-cljs-starter

zackteo 2021-03-24T10:28:02.254300Z

Or maybe this https://github.com/jacekschae/shadow-reagent just that I should remove the proto-repl dependency :thinking_face: cause im using cider and my friends are using calva

nilern 2021-03-24T10:33:41.255900Z

I find templates often just lead to more trouble because then I don't understand the build at all.

thheller 2021-03-24T10:41:13.257100Z

agreed. I think everyone should go through a quickstart like tutorial at least once. be it cljs, figwheel or https://github.com/thheller/shadow-cljs#quick-start

thheller 2021-03-24T10:43:13.259100Z

getting to know the parts involved is essential and templates often invite you to skip those parts just to get you going a little quicker. which in the long run isn't ideal IMHO

zackteo 2021-03-28T10:34:52.316700Z

will do!