This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-28
Channels
- # aleph (3)
- # announcements (3)
- # babashka (8)
- # beginners (12)
- # biff (4)
- # calva (12)
- # clerk (29)
- # clj-kondo (1)
- # clojure (104)
- # clojure-art (1)
- # clojure-austin (5)
- # clojure-berlin (3)
- # clojure-brasil (34)
- # clojure-europe (11)
- # clojure-germany (16)
- # clojure-losangeles (9)
- # clojure-nl (30)
- # clojure-norway (58)
- # clojure-uk (1)
- # core-async (8)
- # cursive (4)
- # data-science (9)
- # datalevin (1)
- # datomic (40)
- # emacs (2)
- # events (3)
- # helix (1)
- # honeysql (3)
- # hugsql (1)
- # hyperfiddle (66)
- # jobs (4)
- # juxt (7)
- # kaocha (9)
- # lsp (5)
- # malli (10)
- # off-topic (4)
- # polylith (2)
- # reitit (5)
- # releases (1)
- # remote-jobs (5)
- # sci (46)
- # scittle (2)
- # shadow-cljs (9)
- # tools-deps (17)
- # xtdb (8)
Hi there, I want to eval a string with sci "(js/Promise.resolve 3)", but I canβt figure out how to setup sci to allow only js/Promise and not the whole js namespace
You can create an object with a js key and Promise inside of that and then provide that under classes
(sci/eval-string "(js/Promise.)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise.resolve 3)" {:classes {'js/Promise js/Promise}})
(sci/eval-string "(js/Promise.resolve 3)" {:classes {'js {'Promise js/Promise}}})
(sci/eval-string "(Promise.resolve 3)" {:classes {'Promise js/Promise}})
(sci/eval-string "(my-promise 3)" {:namespaces {'user {'my-promise js/Promise.resolve}}})
(sci/eval-string "(js/Promise.resolve 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(js/Promise.resolve 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise js/Promise}}})
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise goog.global.Promise}}})
none of them work, but I found one working:
(sci/eval-string "(.resolve js/Promise 3)" {:namespaces {'js {'Promise goog/global.Promise}} :classes {:allow :all}})
classes needs to be a map of symbol to host specific object, so not a clojure data structure
(sci/eval-string "(js/Promise.resolve 3)" {:classes #js {:js #js {:Promise js/Promise}}})
:repl/exception!
;
; Execution error (Error) at (<cljs repl>:1).
; [object Object] is not ISeqable
Ok but in the readme, {:classes {'js goog/global :allow :all}}
it is a clojure map?
oh maybe mix the two
I'm sorry, like this:
cljs.user=> (sci/eval-string "(js/Promise.resolve 1)" {:classes {'js #js {:Promise js/Promise}}})
#object[Promise [object Promise]]
Thanks! I've spent so much time on this
Is there a place in the documentation where you think this might be added so others would save time in the future?
My feelings is there is no doc about this x)
but I would say here https://github.com/babashka/sci#classes
Sure!
Like I could not transpose the JAVA example for js/xxxx
yes, I can see how that is confusing. But globalThis
is basically also a JS object with keys of which Promise is one of the keys, so {'js js/globalThis}
is the global map
yes now I see, but I didn't know that js/
was a valid syntax to access a JS Object (the /
part)
thanks!
(I'll make the issue but in 2 hours I have to rush some code)
hmm, got an error using it
minimal example
(sci/eval-string "(.then (js/Promise.resolve 1) (fn [x]))" {:classes {'js #js {:Promise js/Promise}}})
:repl/exception!
;
; Execution error (ExceptionInfo) at (<cljs repl>:1).
; Method then on function Promise() { [native code] } not allowed!
it's the same error I got from other tries
works, thanks!
I added docs now: https://github.com/babashka/sci#classes
Sorry I forgot to create the issue (should have done it immediately). Very nice tho, very explicit, thanks
I had a silly idea yesterday, and I'm wondering if there's a sci interface to something like eval-string from a vanilla-ish JS environment (details in 𧡠)
so, Gnome has an 'extension' mechanism in what seems to be a tweaked JS environment - you can write javascript that e.g. allows for adding panel items, tweaking how workspace switching works, etc... but from my initial research, it seems to lack an interactive experience (e.g. I want to get the list of panel items and maybe shuffle their positions around or something)... I immediately thought "JS, interactive, sci?"
scittle is what I was looking at as well - is there an 'exported function' at all (as opposed to the script blocks from the examples)? I might just need more hammock time to imagine the picture more clearly
I'm worried I might start using that expression at work and people will be confused, but it'll be an opportunity to shill
This might also be fun to play around with: https://github.com/squint-cljs/cherry/blob/main/doc/embed.md