clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
lilactown 2021-04-25T01:45:17.400800Z

from what I understand, dnolen's project uses React components they write in JS (ostensibly as a library) that their CLJS app consumes

lilactown 2021-04-25T01:45:32.401200Z

they use storybook to document and develop the JS components outside of the app

lilactown 2021-04-25T01:46:28.402300Z

so to copy that strategy, you would create a JS project as a library, setup storybook according to the instructions, and then your CLJS app would use that library

lilactown 2021-04-25T01:47:36.403600Z

an easier way might be to use storybook with your CLJS code. here's an example I built awhile ago: https://github.com/lilactown/storybook-cljs

👍 1
💯 1
lilactown 2021-04-25T01:47:51.404Z

storybook has had several major versions which have actually made this slightly easier to do

lilactown 2021-04-25T01:48:15.404400Z

I think a shadow-cljs version bump also would fix some stuff

sova-soars-the-sora 2021-04-25T21:02:50.407300Z

can i call clojurescript functions from within <script></script> tags?

sova-soars-the-sora 2021-04-25T21:03:04.407600Z

* functions that were compiled into a cljs file

phronmophobic 2021-04-25T21:26:10.408700Z

As long as the compiled js produced from your cljs code is run before the script tag that's using it and you're exporting your cljs functions correctly (see https://clojurescript.org/reference/advanced-compilation#access-from-javascript), then it should work just fine.

sova-soars-the-sora 2021-04-25T22:00:44.408900Z

Hmmm, I keep getting Uncaught ReferenceError: haxattax is not defined

sova-soars-the-sora 2021-04-25T22:01:16.409400Z

in my cljs file i have

(defn haxattax []
	(.log js/console "OH MAN"))

sova-soars-the-sora 2021-04-25T22:01:37.409800Z

and in the HTML file I have

&lt;script src="js/compiled/b_r.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;script&gt;
document.addEventListener("DOMContentLoaded", function(event) {
  haxattax();
});

      

sova-soars-the-sora 2021-04-25T22:02:21.410100Z

do I need to prefix that call with something?

phronmophobic 2021-04-25T22:08:20.410800Z

Yes, you need the namespace (eg. my.ns.haxattax() ) and you should also mark your function for export. See https://clojurescript.org/reference/advanced-compilation#access-from-javascript

(defn ^:export haxattax []
	(.log js/console "OH MAN"))

sova-soars-the-sora 2021-04-25T22:12:49.411700Z

Cool, thanks. I'm still getting b_r is undefined when calling it as b_r.core.haxattax();

sova-soars-the-sora 2021-04-25T22:14:49.412Z

it ought to work on the dev build and not just the minified, right?

phronmophobic 2021-04-25T22:18:38.412800Z

yep. should work in dev build

phronmophobic 2021-04-25T22:19:29.413700Z

I might try and add (.log js/console hasattax) right below the hasattax definition to see if it will print some helpful info

phronmophobic 2021-04-25T22:21:13.414800Z

The other thing I would try is just looking at the js/compiled/b_r.js file and searching for hasattax to see if maybe a build configuration flag is missing somewhere

sova-soars-the-sora 2021-04-25T22:25:01.416200Z

Okay. Yeah I still get b_r is undefined when trying to call b_r.core.haxattax(); so time to check the js file. not certain what build flags would need to be around to make this work... started this using lein figwheel template

sova-soars-the-sora 2021-04-25T22:25:32.416600Z

well, there is no haxattax in the compiled JS file ... 😮

😮 1
phronmophobic 2021-04-25T22:26:42.417700Z

well, there's your problem

phronmophobic 2021-04-25T22:27:15.418300Z

do you have a "main" set for your compilation?

sova-soars-the-sora 2021-04-25T22:27:42.418500Z

I don't see one in project.clj anywhere

sova-soars-the-sora 2021-04-25T22:27:56.418700Z

oh there is :compiler {:main

sova-soars-the-sora 2021-04-25T22:30:01.419100Z

Hmmm. so something about compilation is not including it

phronmophobic 2021-04-25T22:31:08.419500Z

is your main set to b-r.core?

sova-soars-the-sora 2021-04-25T22:31:38.420Z

Yes

phronmophobic 2021-04-25T22:31:39.420100Z

or at least some namespace that requires b-r.core

sova-soars-the-sora 2021-04-25T22:31:59.420400Z

b-r.core is :main

phronmophobic 2021-04-25T22:32:17.420800Z

hmmm, maybe try lein clean and try to recompile?

sova-soars-the-sora 2021-04-25T22:32:52.421200Z

Oh it could be. the dev build outputs to index.js

sova-soars-the-sora 2021-04-25T22:32:57.421400Z

while the min build outputs to b-r.js

sova-soars-the-sora 2021-04-25T22:33:00.421600Z

b_r.js *

phronmophobic 2021-04-25T22:33:25.421700Z

i'm going to start a thread.

sova-soars-the-sora 2021-04-25T22:33:33.422Z

Thank you

phronmophobic 2021-04-25T22:33:49.422200Z

for dev builds, it usually still compiles to multiple files.

phronmophobic 2021-04-25T22:34:21.422400Z

so whether it compiles to index.js as a single file will depend on the optimization setting

phronmophobic 2021-04-25T22:35:38.422600Z

Have you tried recompiling?

sova-soars-the-sora 2021-04-25T22:37:30.422800Z

lein clean and lein figwheel again?

sova-soars-the-sora 2021-04-25T22:38:00.423Z

I did a min build again, but no haxattax in the output js ... hmmm

sova-soars-the-sora 2021-04-25T22:38:35.423200Z

maybe :optimizations :advanced is not right? or maybe I need to preserve source maps or whatever? I vaguely recall this flag..

phronmophobic 2021-04-25T22:39:10.423400Z

usually it shows that it's recompiling a file

phronmophobic 2021-04-25T22:39:16.423600Z

by printing to the console

phronmophobic 2021-04-25T22:39:34.423800Z

it's been a while since I've used lein figwheel

sova-soars-the-sora 2021-04-25T22:39:52.424Z

my friend it flippin worked

1
sova-soars-the-sora 2021-04-25T22:39:53.424200Z

😄

sova-soars-the-sora 2021-04-25T22:40:16.424500Z

plum brandy for everyone in the channel

🍻 1
phronmophobic 2021-04-25T22:40:23.424700Z

whoo!

🥃 1
sova-soars-the-sora 2021-04-25T22:48:44.425100Z

it went back to not working

😦 1
sova-soars-the-sora 2021-04-25T22:53:33.425400Z

i'm gonna use shadow-cljs and see if that rectifies it

sova-soars-the-sora 2021-04-25T23:33:09.425600Z

worked first try shadowcljs

sova-soars-the-sora 2021-04-25T23:33:12.425800Z

woot.

1