This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-03
Channels
- # aleph (1)
- # announcements (3)
- # aws (36)
- # babashka (35)
- # beginners (25)
- # cider (14)
- # clj-kondo (3)
- # clojure (154)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-serbia (1)
- # clojure-uk (133)
- # clojurescript (36)
- # cursive (15)
- # data-science (7)
- # datomic (16)
- # fulcro (34)
- # immutant (9)
- # jackdaw (5)
- # jobs (1)
- # leiningen (39)
- # off-topic (25)
- # pathom (42)
- # planck (13)
- # play-clj (1)
- # re-frame (18)
- # reagent (6)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (16)
- # shadow-cljs (67)
- # sql (22)
- # testing (1)
- # uncomplicate (2)
- # vim (21)
- # vscode (6)
Generating RSS feeds for your static HTML site with bootleg, a CLI tool created with the Small Clojure Interpreter and GraalVM: https://epiccastle.io/blog/generating-xml-with-bootleg/
I've been trying to get js/console
, js/window
, and js/alert
to work in the same magical way as in CLJS. I thought I could do this with a Proxy object, but it seems Sci doesn't like it. The following works under most domains in the browser console:
script = document.createElement('script');
script.onload = function(){ console.log('sci loaded') }; script.setAttribute('src','');
document.body.appendChild(script);
const that = this;
const js = new Proxy({}, {
get: function(obj, prop) {
return that[prop];
}
});
js.window // etc work
// In Sci I cannot get access
sci.evalString(':anything', {namespaces: {js: js}})
=> sci.js:92 Uncaught Error: No protocol method IKVReduce.-kv-reduce defined for type object: [object Window]
sci.evalString('(aget js "console")', {bindings: {js: js}})
=> console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …}
sci.evalString('(.-log (aget js "console") "hello")', {bindings: {js: js}})
=> sci.js:801 Uncaught Al {message: "Method -log on function Object() { [native code] } not allowed!
sci.evalString('js/console', {bindings: {js: js}})
=> sci.js:800 Uncaught Al {message: "Could not resolve symbol: js/console [at line 1, column 1]", data: cb, rc: null, name: "Error", description: undefined, …}
I'm not sure if a case like this fits with the namespace implementation of Sci. I'm curious what you think about supporting this@jeroenvandijk This works for me:
sci.evalString('js/window', {namespaces: {js: {window: window}}})
Ah yes, probably better
Being explicit about what is accessible is a better approach anyway
Thanks!
This also seems to work:
sci.evalString('(.log (.-console window) "hello" "there")', {classes: {allow: true, window: window}})
I'm not sure why it also logs the console object itself as well.. maybe a bugallow true is not documented, just a hack to turn off permission check... might change
instead of (apply method obj args)
maybe it should say: (apply method args)
? JS interop is terribly confusing to me
Yeah I understand, I'm confused too 🙂 But thanks, I'll play with these suggestions and give some feedback later
I would be happy if Sci is not (too) different from Cljs in order to have no real switch
How would you use that in this case?
well, in theory. I think it's not yet picked up by the JS API:
sci.evalString('#?(:jeroen (.log (.-console window)))', {classes: {allow: true, window: window}, features: ["jeroen"]})
should be added here: https://github.com/borkdude/sci/blob/master/src/sci/impl/js.cljs
and the value for :features
should be translated into a set of keywords
Ah cool
it will be passed to edamame: https://github.com/borkdude/edamame where this is documented
come to think of it maybe edamame should not use a set so you can give a priority in a given order, but so far I haven't needed that
ah, I just copied that option from tools.reader: > :features - persistent set of feature keywords for reader conditionals
I'm trying to understand how the reader conditionals would help in this case? Do you mean this could cover for the difference between nodejs and browser js for instance?
> I would be happy if Sci is not (too) different from Cljs in order to have no real switch
Ah yeah makes sense, thanks
@deleted-user bootleg also has a glob function: https://epiccastle.io/blog/generating-xml-with-bootleg/ maybe you can just borrow that one or use it as inspiration for fs
@retrogradeorbit is also in here btw (author of that stuff)
@deleted-user what does it mean in the readme: > the Babashka support is not quite done yet. is there something in bb that is missing?
@borkdude How do you debug the compiled Clojurescript? I'm using Figwheel now to get proper error messages
@jeroenvandijk I usually do it like this:
$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}}' -m cljs.main -re node -e "(require '[sci.core :as sci]) (sci/eval-string \":foo\")"
:foo
Ah yeah makes sense
I'm doing some exotic cljs specific stuff now and I feel the pain of compiled cljs. But with figwheel it's much better now