Fork me on GitHub
#sci
<
2020-11-25
>
mkvlr09:11:59

is ctx in sci a mutable thing? It’s stored in an atom here https://github.com/babashka/xterm-sci/blob/a8e16f35a2b77a006b64f90e5a40f3a39e3c9f94/src/xterm_sci/core.cljs#L28 but I can’t see where it’s being reset!?

borkdude09:11:00

yes, ctx is mutable and eval-string will mutate it

mkvlr09:11:33

ok, any reason for storing it in an atom?

borkdude09:11:57

in that code it might not be needed

borkdude09:11:12

there are reasons to do this, if you e.g. use functions in the opts that need the ctx, so you will have a circular dependency. I often use a volatile for this

borkdude09:11:00

but in this specific example, I think you could get rid of the atom

mkvlr09:11:33

ok thanks

mkvlr09:11:13

and setting :classes {'js goog/global} should make js/ work just like in bootstrap cljs?

borkdude09:11:21

it works to a degree, but it's best to write some tests for that to verify the details of that. I'm not an expert in CLJS interop :)

borkdude09:11:49

The example is hosted here, so you can try: https://babashka.org/xterm-sci/

mkvlr09:11:59

I was confused at first that js/window interpreted in sci is the same as a bining {'js-window js/window} but that’s probably because I don’t understand dynamic scope

mkvlr09:11:20

I checked that it is the same window…

borkdude09:11:02

sorry, I don't understand your message about js-window

mkvlr09:11:16

not sure I do, given the opts {:classes {'js js/window} :bindings {'js-window js/window}}

mkvlr09:11:38

(= js-window js/window) evalutates to true

mkvlr09:11:29

I guess this is more a js question

mkvlr09:11:15

I don’t get what all those windows are, but it seems to work

😄 3
borkdude09:11:56

is js-window a thing in CLJS? why have you given it that name?

mkvlr09:11:54

yep, but I want all of js/

mkvlr09:11:47

yep, that’s what I’m doing

borkdude09:11:15

then you don't need this right? :bindings {'js-window js/window} - that's the part I'm confused about

mkvlr09:11:41

no, this was just for testing that js/window interpreted returns the right thing

borkdude09:11:25

I notice this works in cljs:

cljs.user=> js/location.href
""
but in sci this currently doesn't:
user=> js/location.href
nil
user=> (.-href js/location)
""
user=> 

mkvlr09:11:05

right, same for e.g. (.-body js/document) (works) vs js/document.body (returns nil)

borkdude09:11:34

I think we can fix this in sci, but I'm not sure if js/document.body is officially supported by CLJS (although it obviously works)

borkdude09:11:52

if there are any official docs for this, I will consider a fix

mkvlr09:11:07

I’ll see if I can find them

mkvlr09:11:42

is there a way to support the #js reader tag currently?

borkdude09:11:38

I think that should already be supported by default in sci. It doesn't work for you?

borkdude09:11:52

hmm, it's returning something weird:

user=> #js [1 2 3]
#object[JW [object Object]]

borkdude09:11:26

this does work:

user=> (clj->js [1 2 3])
#js [1 2 3]

borkdude09:11:33

Feel free to post issues about this

mkvlr09:11:13

will do thanks

mkvlr13:11:47

@borkdude I see you fixed this already in sci, thank you! Is there a prerelease jar I can grab somewhere already?

borkdude13:11:17

@mkvlr you can use it as a git dep if you're using deps.edn?

mkvlr13:11:25

oh yes I am

mkvlr13:11:35

will do, thanks!

borkdude13:11:40

I'm also doing that in the sci xterm project