sci

arohner 2025-01-24T22:09:47.281449Z

Apologies, my JS is not very strong. I’m trying to write a webapp using scittle. I’d like to dynamically load some CLJS, so I have

arohner 2025-01-24T22:13:05.171569Z

the console says “foo not defined”, but if I wait a second and type it in again, foo is defined. I believe what’s happening is the second script is running before the CLJS has finished evaluating. Is there any way to stop that race?

arohner 2025-01-24T22:20:25.888889Z

Oh, duh, changing the second script to x-scittle makes the problem go away, but the more general problem of js calling cljs still exists

borkdude 2025-01-24T22:28:53.513189Z

<script> is synchronous by default, so the above should work in the order like you'd expect it to be

borkdude 2025-01-24T22:32:37.623129Z

of course you still need to make the function foo accessible to JS

arohner 2025-01-24T22:32:55.946299Z

right, but what tripped me up is is not , because scittle uses its own XMLHttpRequest

borkdude 2025-01-24T22:33:13.380289Z

oh that makes sense

borkdude 2025-01-24T22:33:49.680679Z

there is a way to manually evaluate the script tags, perhaps that works for you, let me check the API

arohner 2025-01-24T22:34:30.138009Z

eval-script-tags* could work, but it’s not exported

arohner 2025-01-24T22:34:44.974169Z

and suboptimally, requires creating a new DOM node to use

borkdude 2025-01-24T22:38:06.441959Z

the way to do this is this: call this function:

scittle.core.disable_auto_eval()
first, to disable what it says. And then: (scittle.core.eval_script_tags ...) on the dots you can place the result of a querySelector, or if you don't provide anything, it'll just evaluate all the application/x-scittle ones. Unfortunately currently it doesn't return a promise such that you could chain your JS evaluation, but that could be fixed

borkdude 2025-01-24T22:40:35.937899Z

Another way to work with this is perhaps first define your JavaScript and then call a callback from your CLJS scittle code

arohner 2025-01-24T22:41:12.495179Z

staying only in scittle for now is an option

arohner 2025-01-24T22:41:19.580429Z

Thanks! sci and scittle are both excellent

❤️ 1
borkdude 2025-01-24T22:44:33.105689Z

<script type="application/javascript"
   var data = ...;
   window.doit = () => window.foo(data);
</script>
<script type="application/x-scittle">
(defn foo [data] ...)
(set! (.-foo js/window) foo)
(js/window.doit)
</script>