from what I understand, dnolen's project uses React components they write in JS (ostensibly as a library) that their CLJS app consumes
they use storybook to document and develop the JS components outside of the app
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
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
storybook has had several major versions which have actually made this slightly easier to do
I think a shadow-cljs version bump also would fix some stuff
can i call clojurescript functions from within <script></script> tags?
* functions that were compiled into a cljs file
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.
Hmmm, I keep getting Uncaught ReferenceError: haxattax is not defined
in my cljs file i have
(defn haxattax []
(.log js/console "OH MAN"))
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();
});
do I need to prefix that call with something?
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"))
Cool, thanks. I'm still getting b_r is undefined when calling it as b_r.core.haxattax();
it ought to work on the dev build and not just the minified, right?
yep. should work in dev build
I might try and add (.log js/console hasattax)
right below the hasattax
definition to see if it will print some helpful info
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
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
well, there is no haxattax
in the compiled JS file ... 😮
well, there's your problem
do you have a "main" set for your compilation?
I don't see one in project.clj
anywhere
oh there is :compiler {:main
Hmmm. so something about compilation is not including it
is your main set to b-r.core
?
Yes
or at least some namespace that requires b-r.core
b-r.core is :main
hmmm, maybe try lein clean
and try to recompile?
Oh it could be. the dev build outputs to index.js
while the min build outputs to b-r.js
b_r.js *
i'm going to start a thread.
Thank you
for dev builds, it usually still compiles to multiple files.
so whether it compiles to index.js as a single file will depend on the optimization setting
Have you tried recompiling?
lein clean
and lein figwheel
again?
I did a min build again, but no haxattax in the output js ... hmmm
maybe :optimizations :advanced is not right? or maybe I need to preserve source maps or whatever? I vaguely recall this flag..
usually it shows that it's recompiling a file
by printing to the console
it's been a while since I've used lein figwheel
my friend it flippin worked
😄
plum brandy for everyone in the channel
whoo!
it went back to not working
i'm gonna use shadow-cljs and see if that rectifies it
worked first try shadowcljs
woot.