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!
?
yes, ctx is mutable and eval-string will mutate it
ok, any reason for storing it in an atom?
in that code it might not be needed
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
but in this specific example, I think you could get rid of the atom
ok thanks
and setting :classes {'js goog/global}
should make js/
work just like in bootstrap cljs?
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 :)
The example is hosted here, so you can try: https://babashka.org/xterm-sci/
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
I checked that it is the same window…
sorry, I don't understand your message about js-window
not sure I do, given the opts {:classes {'js js/window} :bindings {'js-window js/window}}
(= js-window js/window)
evalutates to true
I guess this is more a js question
I don’t get what all those windows are, but it seems to work
is js-window
a thing in CLJS? why have you given it that name?
@mkvlr you can also mock out all the objects you want to give access to like this: https://github.com/borkdude/sci/blob/c2045f5e56f6c52f05921eaff9d70d64ac971c98/test/sci/interop_test.cljc#L94
yep, but I want all of js/
so maybe then this is the best option: https://github.com/babashka/xterm-sci/blob/a8e16f35a2b77a006b64f90e5a40f3a39e3c9f94/src/xterm_sci/core.cljs#L17
yep, that’s what I’m doing
then you don't need this right? :bindings {'js-window js/window}
- that's the part I'm confused about
no, this was just for testing that js/window
interpreted returns the right thing
ok
TIL
I notice this works in cljs:
cljs.user=> js/location.href
"<http://localhost:1339/>"
but in sci this currently doesn't:
user=> js/location.href
nil
user=> (.-href js/location)
"<https://babashka.org/xterm-sci/>"
user=>
If you want to allow everything, you will probably also need to add: https://github.com/babashka/xterm-sci/blob/37bd9bceb38c1e76a40ce584fc2b4fbdc201bd36/src/xterm_sci/core.cljs#L18
right, same for e.g. (.-body js/document)
(works) vs js/document.body
(returns nil)
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)
if there are any official docs for this, I will consider a fix
I’ll see if I can find them
is there a way to support the #js
reader tag currently?
I think that should already be supported by default in sci. It doesn't work for you?
hmm, it's returning something weird:
user=> #js [1 2 3]
#object[JW [object Object]]
this does work:
user=> (clj->js [1 2 3])
#js [1 2 3]
Feel free to post issues about this
will do thanks
https://github.com/borkdude/sci/issues/449 & https://github.com/borkdude/sci/issues/450
thanks
@borkdude I see you fixed this already in sci, thank you! Is there a prerelease jar I can grab somewhere already?
@mkvlr you can use it as a git dep if you're using deps.edn?
oh yes I am
will do, thanks!
I'm also doing that in the sci xterm project