Fork me on GitHub

Generating RSS feeds for your static HTML site with bootleg, a CLI tool created with the Small Clojure Interpreter and GraalVM:

👍 3

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','');


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


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


allow 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


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


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


you can use reader conditionals too btw.


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: and the value for :features should be translated into a set of keywords


it will be passed to 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


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


Ah yeah makes sense, thanks


@nate_clojurians bootleg also has a glob function: maybe you can just borrow that one or use it as inspiration for fs

👍 1
Nate Sutton12:02:27

oh, rad, thanks :)


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

Nate Sutton12:02:56

there also might be a place for a walk with a regex, too. I'm still thinking about it

Nate Sutton12:02:57

or maybe a function that determines if they match, and then the seq of matches can be consumed ¯\(ツ)

Nate Sutton12:02:10

but that's a bit different than globs


@nate_clojurians what does it mean in the readme: > the Babashka support is not quite done yet. is there something in bb that is missing?

Nate Sutton13:02:06

yep, there is at least one missing class but probably more. I was going to finish out tests and docs then start adding stuff to babashka and/or changing the lib to better support babashka


@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\")"


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


I like figwheel(.main) a lot