Fork me on GitHub
#babashka
<
2020-02-03
>
borkdude07:02:35

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/

👍 12
jeroenvandijk08:02:15

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

borkdude09:02:26

@jeroenvandijk This works for me:

sci.evalString('js/window', {namespaces: {js: {window: window}}})

jeroenvandijk09:02:54

Ah yes, probably better

jeroenvandijk09:02:48

Being explicit about what is accessible is a better approach anyway

borkdude09:02:15

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 bug

borkdude09:02:48

allow true is not documented, just a hack to turn off permission check... might change

borkdude09:02:27

instead of (apply method obj args) maybe it should say: (apply method args)? JS interop is terribly confusing to me

jeroenvandijk09:02:33

Yeah I understand, I'm confused too 🙂 But thanks, I'll play with these suggestions and give some feedback later

borkdude09:02:59

ok, feel free to experiment. you can build the final js with script/build-js

jeroenvandijk09:02:00

I would be happy if Sci is not (too) different from Cljs in order to have no real switch

borkdude09:02:09

you can use reader conditionals too btw.

jeroenvandijk09:02:45

How would you use that in this case?

borkdude09:02:14

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"]})

borkdude09:02:21

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

borkdude09:02:37

it will be passed to edamame: https://github.com/borkdude/edamame where this is documented

borkdude09:02:07

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

borkdude09:02:44

ah, I just copied that option from tools.reader: > :features - persistent set of feature keywords for reader conditionals

jeroenvandijk09:02:31

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?

borkdude09:02:17

> I would be happy if Sci is not (too) different from Cljs in order to have no real switch

borkdude09:02:41

to cover for those cases where sci is still different, until we fixed it?

jeroenvandijk09:02:37

Ah yeah makes sense, thanks

borkdude10:02:31

@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

👍 4
borkdude12:02:15

@retrogradeorbit is also in here btw (author of that stuff)

borkdude12:02:05

@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?

jeroenvandijk16:02:13

@borkdude How do you debug the compiled Clojurescript? I'm using Figwheel now to get proper error messages

borkdude16:02:57

@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

jeroenvandijk16:02:27

Ah yeah makes sense

jeroenvandijk16:02:09

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

borkdude16:02:28

I like figwheel(.main) a lot