scittle

chromalchemy 2022-10-27T02:19:48.567779Z

Can one call scittle functions from external js code (js file or module)?

borkdude 2022-10-27T06:43:08.890809Z

@chromalchemy Yes, just define them on the global window. This is the first example on the scittle docs.

chromalchemy 2022-10-27T16:34:45.197279Z

Ok thanks. I had tried that, but was getting “function undefined” errors. I think the problem was I had to put the calling function behind window.onload

window.onload = function(){
   test_fn('Hello from JS script tag');
}

chromalchemy 2022-10-27T16:35:20.458379Z

This is working: HTML

<script src="" type="application/javascript"></script>

<script type="application/x-scittle" src="cljs/mycljs.cljs"></script>

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

<button onclick="test_fn('Hello from HTML Button')">
    Click me!
</button>
CLJS
(ns mycljs)

(defn test-fn [s]
  (js/console.log s))

;; export function to use from JavaScript:
(set! (.-test_fn js/window) test-fn)

(test-fn "Hello from Scittle file")
JS
window.onload = function(){
   test_fn('Hello from JS file');
}
log
> Hello from Scittle file
> Hello from JS file
> Hello from HTML Button (on click)
simple_smile

borkdude 2022-10-27T16:35:51.439459Z

ah ok

chromalchemy 2022-10-27T18:41:04.052329Z

It seemed to require window.onload if the js caller fn was in another script tag, or script tag with source js file. The scittle repo example does work as is for invocation from html-tag.

borkdude 2022-10-27T18:43:47.827229Z

ah right