clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
macrobartfast 2020-10-15T00:34:32.466600Z

after creating a project with

lein new re-frame demorf +cider
and then
lein deps
and
npm install
and then running in emacs
cider-jack-in-cljs
I got a user> prompt, but attempting to eval the :require statement in core.cljs with
cider-eval-defun-at-point
generated
Unhandled java.io.FileNotFoundException
   Could not locate reagent/dom__init.class, reagent/dom.clj or
   reagent/dom.cljc on classpath.
which I assume will apply to every dependency. How should I start troubleshooting this?

macrobartfast 2020-10-15T17:44:14.491200Z

@p-himik I asked you to turn Slack notifications on high volume next to you when sleeping.

macrobartfast 2020-10-15T17:44:23.491400Z

don’t let it happen again.

p-himik 2020-10-15T17:46:20.491600Z

Aye aye captain.

macrobartfast 2020-10-15T17:46:21.491800Z

Good for you on Vim. My Emacs addiction is a questionable one. The Boot crowd were Vim users, I noticed.

macrobartfast 2020-10-15T17:52:18.492300Z

I have a question for you or @dpsutton though… I assume the cljs repl is evaluating in the browser, right?

macrobartfast 2020-10-15T17:52:27.492500Z

or is it spinning up a node instance or something?

macrobartfast 2020-10-15T17:53:57.492700Z

evaluating the :require in server.clj is working great (I get my familiar ‘nil’ response) but doing the same in core.cljs is not producing a response…

macrobartfast 2020-10-15T17:55:54.492900Z

nor evaluating (+ 1 1)… unless I change the Emacs mode for the core.cljs buffer to ‘clojure-mode’, in which case (+ 1 1) evaluates ok, but I get an error on the :require statement (can’t find the first dependency).

macrobartfast 2020-10-15T17:56:09.493100Z

could be more of an Emacs integration thing.

macrobartfast 2020-10-15T18:01:28.493700Z

basically, having issues with the cljs buffer evaluation. evaluating (js/alert "foo") from within core.cljs throws ‘no such namespace’. I noticed that that prompt was demorf2.repl> as opposed to the demorf2.server I saw in @dpsutton’s screenshot.

macrobartfast 2020-10-15T18:08:52.494800Z

I’m not up to speed on Slackiquette… I probably should post each new issue in a channel as opposed to hammering you two just because you were so helpful yesterday. I’ll try to do that.

dpsutton 2020-10-15T18:10:19.495Z

so its important to remember that there are two repls: clj and cljs. CIDER unfortunately only knows how to eval forms in the last repl that your cursor was in. so click in the cljs repl and then click in the cljs buffer and eval (js/alert "hi from cljs") or something and it should work

macrobartfast 2020-10-15T18:11:51.495200Z

aha… works!!

dpsutton 2020-10-15T18:12:50.495400Z

and the repl namespace is important if you are sending forms to the repl buffer but not if you are just evaluating inline. i put mine into the demorf2/server buffer to call the -main function is all

macrobartfast 2020-10-15T18:40:44.497Z

gotcha!

macrobartfast 2020-10-15T18:41:28.497200Z

I have been putting calls to -main in comment blocks for inline evaluation, but that sounds better.

dpsutton 2020-10-15T00:41:58.466700Z

that template does weird stuff. it uses lein-shadow, a plugin that (imo) just adds more layers to tooling for no real benefit

dpsutton 2020-10-15T00:42:45.466900Z

that template doesn't include react, react-dom and create-react-class, all of which are necessary for shadow.

dpsutton 2020-10-15T00:46:09.467100Z

can i recommend lein new reagent demorf2 +shadow-cljs over what you are using? and then add re-frame from there?

p-himik 2020-10-15T00:56:07.467300Z

> that template doesn't include react, react-dom and create-react-class, all of which are necessary for shadow. Not sure I get that. How is React necessary for shadow-cljs? Also, the need for create-react-class is no longer there with modern versions of React.

p-himik 2020-10-15T00:56:49.467500Z

Ah, you probably meant the way shadow-cljs works with cljsjs.

dpsutton 2020-10-15T00:58:56.469Z

Yeah it doesn’t bring in the cljsjs versions and uses the npm distributed packages. Those are conspicuously absent from the package.json file though

👍 1
macrobartfast 2020-10-15T01:07:41.469300Z

@dpsutton you can definitely recommend another template!

macrobartfast 2020-10-15T01:07:48.469500Z

I will try that.

macrobartfast 2020-10-15T01:35:58.469700Z

in the reagent template, ran into a

Unhandled java.lang.Exception
   Failed to launch Figwheel CLJS REPL: nREPL connection found but
   unable to load piggieback.  This is commonly caused by A) not
   providing piggieback as a dependency and/or B) not adding
   piggieback middleware into your nrepl middleware chain.
error, so found https://github.com/reagent-project/reagent-template/issues/111

macrobartfast 2020-10-15T01:36:29.470Z

assuming you use emacs, how would you go about setting up an environment that allows you to evaluate code in a buffer?

macrobartfast 2020-10-15T01:36:53.470200Z

I’ll admit, I’m fully confused these days by the options available.

macrobartfast 2020-10-15T01:37:43.470400Z

I used to just connect to an nrepl instance in a terminal to evaluate Clojure, but now it seems it’s recommended to jack in.

macrobartfast 2020-10-15T01:38:23.470600Z

I never know whether I should jack in to just clj, or clj&cljs.

macrobartfast 2020-10-15T01:45:10.470800Z

@dpsutton @p-himik if either of you know of a quick start or demo app that uses re-frame/reagent with a working current approach, be sure to let me know!

macrobartfast 2020-10-15T01:45:27.471Z

it seems like a lot of the demo projects are maybe not current.

macrobartfast 2020-10-15T01:45:58.471200Z

unfortunately for me, lots of tutorials seem to use Calva, alas… maybe I should consider switching.

dpsutton 2020-10-15T01:49:02.471400Z

can you tell me the exact command you used to create your template?

macrobartfast 2020-10-15T01:52:04.471600Z

lein new reagent demorf2 +shadow-cljs +cider

macrobartfast 2020-10-15T01:52:27.471800Z

I added cider because I figured I needed it, but I’m pretty lost in the ecosystem now…

macrobartfast 2020-10-15T01:53:10.472Z

basically, I’m trying to have an environment wherein I can evaluate code from statements in the buffer (as opposed to the repl(s) themselves.

dpsutton 2020-10-15T01:53:36.472200Z

i'm confused why you're talking about figwheel then

dpsutton 2020-10-15T01:53:42.472400Z

if you are using +shadow-cljs

dpsutton 2020-10-15T01:58:00.472600Z

dpsutton 2020-10-15T01:58:11.473Z

dpsutton 2020-10-15T01:58:20.473400Z

works for me

dpsutton 2020-10-15T02:01:12.473600Z

1. lein new reagent demorf2 +shadow-cljs (drop +cider. cider knows what to do) 2. cd demorf2 && npm i get our deps 3. open up server.clj and cider-jack-in. make sure to choose lein for this when asked which to use this uses a server to serve our assets. so start the server up otherwise no way to get our js. (not technically true as shadow can serve this but we're gonna use the backend provided) 4. go to core.cljs and cider-jack-in-cljs and choose shadow-cljs when jacking in. it should then ask you which build tool you are using and select shadow. Then it will ask you which build to use and select :app. Load the port specified in server.clj (i changed it to 3002 as the default 3000 was already in use) 5. visit localhost:3000 (or whatever port you are using)

dpsutton 2020-10-15T02:02:29.473800Z

its a lot but you get used to it when you understand what's going on. i looked at the template and saw there were backend files and a jetty server so fire that up. then go fire up cljs. this template uses shadow-cljs for the frontend and lein for the backend shadow-cljs.edn and project.clj files respectively so those are the build tools to select for frontend and backend

dpsutton 2020-10-15T02:12:47.474100Z

i hope that clears it up @macrobartfast

macrobartfast 2020-10-15T02:20:38.474300Z

I’ll try it now! thank you so much! I was thinking about figwheel and shadow-cljs because I didn’t yet understand they were alternatives.

macrobartfast 2020-10-15T02:21:51.474500Z

I’ll give your approach a try; if it works, I’ll be having your instructions etched into titanium and wall mounted in an oak frame.

macrobartfast 2020-10-15T02:43:33.474700Z

omg omg omg :star-struck:

macrobartfast 2020-10-15T02:43:47.474900Z

It worked. I’m so completely grateful.

dpsutton 2020-10-15T02:46:35.475200Z

i'm glad. there's lots of pieces that when just starting can be really confusing to figure out. i wrote out in addition to the steps i took also the way i figured out what steps to do so i hope that helps

macrobartfast 2020-10-15T03:02:10.475400Z

and I’m really grateful for the latter.

macrobartfast 2020-10-15T03:02:21.475600Z

(as well as the former, of course)

macrobartfast 2020-10-15T03:02:57.475800Z

getting a project running is often my stumbling block (granted, I use Emacs, which I guess makes it a bit more tricky)

macrobartfast 2020-10-15T03:03:11.476Z

but… long live Emacs!

p-himik 2020-10-15T06:58:55.476200Z

Sorry I wasn't here to help, was asleep. But I use vim either way. :D

nickt 2020-10-15T12:45:23.479Z

hey y'all, quick question. I have a defrecord that I'm using in my code, and at some point I want interop with js so I cljs->js and a .stringify js/jSON. I'm wondering, is there a way to then do the reverse? From that json stringified string, do a .parse js/JSOn, and a js->cljs and recover the fact that some of those objects are actually records?

nickt 2020-10-15T12:48:05.479700Z

or maybe I can go from my record (which has an array of other records as children) to some string representation and back safely? I don't need JSON specifically

thheller 2020-10-15T12:51:12.479900Z

> I don't need JSON specifically

thheller 2020-10-15T12:51:17.480100Z

why are you converting to JSON then?

nickt 2020-10-15T12:52:14.480300Z

I just need to get to a string representation

nickt 2020-10-15T12:52:18.480600Z

(and back)

nickt 2020-10-15T12:52:38.481200Z

and JSON seemed like the answer until I realized the fact that these objects are actually records is lost

thheller 2020-10-15T12:53:13.481400Z

most common and best option is https://github.com/cognitect/transit-cljs

thheller 2020-10-15T12:53:53.482Z

for records you'll need to add a custom read/write handler but thats quite easy to do

thheller 2020-10-15T12:54:41.482600Z

or just pr-str + cljs.reader/read-string works too

nickt 2020-10-15T12:57:10.482800Z

ah neat

nickt 2020-10-15T12:57:15.483100Z

(read-string (pr-str (Node. 1 2 3)))

nickt 2020-10-15T12:57:23.483400Z

that doesn't seem to work in my repl?

thheller 2020-10-15T12:57:47.483700Z

records need special attention

nickt 2020-10-15T12:59:20.484100Z

hm mind pointing me to some docs on that?

thheller 2020-10-15T13:01:16.484700Z

sorry busy. record needs to implement IPrintWithWriter protocol and cljs.reader needs tag reader.

thheller 2020-10-15T13:01:32.484900Z

better go with transit though

victorb 2020-10-15T13:20:49.485500Z

@nickt otherwise pprint should be able to handle records

victorb 2020-10-15T13:21:13.486Z

team up with with-out-str to get a string version of it. (with-out-str (pprint my-record)

victorb 2020-10-15T13:21:43.486400Z

although if you do read-string with pprint output you'll get a map back, not a record

nickt 2020-10-15T13:22:14.486700Z

yea I get a map back from json too 😕

nickt 2020-10-15T13:22:18.486900Z

definitely need the record

victorb 2020-10-15T13:22:44.487200Z

yeah, you'll need tag readers then, and proper EDN

victorb 2020-10-15T13:23:33.487400Z

maybe https://www.compoundtheory.com/clojure-edn-walkthrough/ would help

victorb 2020-10-15T13:24:11.487900Z

^ has examples of how you can use Records+EDN together for de/serialization

nickt 2020-10-15T13:34:28.488100Z

ok great, thanks. Does cljs have edn?

victorb 2020-10-15T13:44:37.488500Z

@nickt yeah, ships with clojure core, available as clojure.edn , eh, but now when I think about it, not sure if it's included in cljs core actually. Only used cljs.reader/read with EDN in the past in cljs

yogthos 2020-10-15T17:34:48.491100Z

I'm trying to use fullcalendar-react NPM module, but I get an error when trying to require it, looks like cljs compiler is trying to parse a CSS file that's required in one of the js files in the module, is there any workaround for this?

Errors encountered while trying to parse file
  node_modules/@fullcalendar/common/main.css
  {:line 4, :column 1, :message "primary expression expected"}
[:app] Compiling ...
[:app] Build failure:
Failed to inspect file
  node_modules/@fullcalendar/common/main.css

it was required from
  node_modules/@fullcalendar/common/main.js

p-himik 2020-10-15T17:51:01.492Z

I think you have installed a version of the package that requires additional building. You can install a prebuilt package with npm i fullcalendar - it should not have that problem.

thheller 2020-10-15T18:00:25.493300Z

you can also set :js-options {:ignore-asset-requires true} so it just ignores the css

thheller 2020-10-15T18:00:37.493500Z

but the css is also going to be missing 😉

yogthos 2020-10-15T18:05:32.494Z

ah thanks, let me play around with that

yogthos 2020-10-15T18:06:51.494200Z

@p-himik my understanding is that there's fullcalendar and fullcalendar-react, or does fullcalendar-react leverage fullcalendar?

yogthos 2020-10-15T18:07:18.494400Z

currently, I've got

"@fullcalendar/core": "^5.3.1",
    "@fullcalendar/daygrid": "^5.3.1",
    "@fullcalendar/interaction": "^5.3.1",
    "@fullcalendar/react": "^5.3.1",
    "@fullcalendar/timegrid": "^5.3.1"

p-himik 2020-10-15T18:13:32.495600Z

Did you install all those manually? If so, try removing all that and installing just fullcalendar. https://fullcalendar.io/docs/getting-started

yogthos 2020-10-15T18:16:06.495900Z

so that's the non react version

yogthos 2020-10-15T18:16:34.496100Z

this one's the react one https://fullcalendar.io/docs/react

p-himik 2020-10-15T18:18:59.496400Z

I would try installing fullcalendar and @fullcalendar/react then. If that doesn't work, I'd try to figure out how that package works. Finally, if that doesn't make it clearer, I would go with the solution suggested by thheller above with a manual inclusion of all the styles and whatnot.

yogthos 2020-10-15T18:23:42.496600Z

👍

yogthos 2020-10-15T18:32:26.496800Z

@thheller is it possible to ignore assets for a specific module?

thheller 2020-10-15T19:08:26.497400Z

doesn't matter if you ignore one or all. the build will just fail.

yogthos 2020-10-15T19:19:01.497600Z

so adding :ignore-asset-requires does solve the problem with the error, but I was wondering if that might negatively affect other modules like say antd that include assets

thheller 2020-10-15T19:27:10.497800Z

shadow-cljs does not support bundling any kind of "assets"

thheller 2020-10-15T19:27:48.498Z

I made the default to fail the build if any libs does this so you at least know

thheller 2020-10-15T19:28:14.498200Z

so the only difference when ignoring is that it doesn't fail

thheller 2020-10-15T19:28:20.498400Z

but you are not missing any files because of it

yogthos 2020-10-15T20:08:56.498600Z

oh I see, thanks for the explanation sounds like I should be all set with that then

yogthos 2020-10-15T20:09:08.498800Z

and I can just include the assets manually