Fork me on GitHub
#clojurescript
<
2021-04-25
>
lilactown01:04:17

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

lilactown01:04:32

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

lilactown01:04:28

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

lilactown01:04:36

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

💯 3
👍 3
lilactown01:04:51

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

lilactown01:04:15

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

sova-soars-the-sora21:04:50

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

sova-soars-the-sora21:04:04

* functions that were compiled into a cljs file

phronmophobic21:04:10

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-sora22:04:44

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

sova-soars-the-sora22:04:16

in my cljs file i have

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

sova-soars-the-sora22:04:37

and in the HTML file I have

<script src="js/compiled/b_r.js" type="text/javascript"></script>

    <script>
document.addEventListener("DOMContentLoaded", function(event) {
  haxattax();
});

      

sova-soars-the-sora22:04:21

do I need to prefix that call with something?

phronmophobic22:04:20

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-sora22:04:49

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

sova-soars-the-sora22:04:49

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

phronmophobic22:04:38

yep. should work in dev build

phronmophobic22:04:29

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

phronmophobic22:04:13

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-sora22:04:01

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-sora22:04:32

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

😮 2
phronmophobic22:04:42

well, there's your problem

phronmophobic22:04:15

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

sova-soars-the-sora22:04:42

I don't see one in project.clj anywhere

sova-soars-the-sora22:04:56

oh there is :compiler {:main

sova-soars-the-sora22:04:01

Hmmm. so something about compilation is not including it

phronmophobic22:04:08

is your main set to b-r.core?

phronmophobic22:04:39

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

phronmophobic22:04:17

hmmm, maybe try lein clean and try to recompile?

sova-soars-the-sora22:04:52

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

sova-soars-the-sora22:04:57

while the min build outputs to b-r.js

phronmophobic22:04:25

i'm going to start a thread.

phronmophobic22:04:49

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

phronmophobic22:04:21

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

phronmophobic22:04:38

Have you tried recompiling?

sova-soars-the-sora22:04:30

lein clean and lein figwheel again?

sova-soars-the-sora22:04:00

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

sova-soars-the-sora22:04:35

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

phronmophobic22:04:10

usually it shows that it's recompiling a file

phronmophobic22:04:16

by printing to the console

phronmophobic22:04:34

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

sova-soars-the-sora22:04:52

my friend it flippin worked

toot 2
sova-soars-the-sora22:04:16

plum brandy for everyone in the channel

🍻 2
sova-soars-the-sora22:04:44

it went back to not working

😦 2
sova-soars-the-sora22:04:33

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

sova-soars-the-sora23:04:09

worked first try shadowcljs