Fork me on GitHub
#sci
<
2021-09-20
>
borkdude13:09:38

🙌 4
kiranshila18:09:25

Is there a way to use scittle in the body of a document (ie. dynamically)?

borkdude18:09:13

@me1310 can you make a sketch of what you are trying to do?

kiranshila18:09:44

Yes! I'm getting it all spun up now to make sure I'm not crazy haha 🙂

kiranshila19:09:08

Alright, so this might be a little crazy - but I'm playing with Pluto.jl which is a reproducible notebook for Julia, and it has the ability to run JS in the cells to create custom UI components. My goal here is to try to use cljs to write the components instead of js.

kiranshila19:09:02

In the cells, I try to do the example of creating my-alert from the docs but am getting a "Couldn't execute script" error

kiranshila19:09:07

The JS is being run through a async call

let execute_dynamic_function = async ({ environment, code }) => {
    // single line so that we don't affect line numbers in the stack trace
    const wrapped_code = `"use strict"; return (async () => {${code}})()`

    let { ["this"]: this_value, ...args } = environment
    let arg_names = Object.keys(args)
    let arg_values = Object.values(args)
    const result = await Function(...arg_names, wrapped_code).bind(this_value)(...arg_values)
    return result
}

kiranshila19:09:59

Oh wait, yeah that throws out the script type

kiranshila19:09:05

I guess that leads me to my next question - is there a way to call scittle without the script tag, like through a JS interface?

borkdude19:09:59

@me1310 there is a JS interface, but intentionally not well documented yet, so early adopters can test it out first :) https://github.com/borkdude/scittle/blob/main/src/scittle/core.cljs See ^:export

borkdude19:09:58

e.g. there is eval_string

kiranshila19:09:19

Ah brilliant!

kiranshila19:09:10

Excellent! Thank you!

🎉 2