Fork me on GitHub
#sci
<
2020-08-18
>
bbss05:08:37

I've got an issue with clojurescript sci, I'm trying to use d3.js as a :binding in a function that sci compiled. With d3.js it's normal to first grab a bunch of dom elements that you want to use and then apply some operations e.g.

(-> (.select d3 "body")
    (.append "svg")
    (.style  "z-index" 30)
    (.style  "position" "absolute")
    (.style  "background" "tomato")
    (.append "g")
    (.call (-> (.brushX d3)
               (.extent #js [#js [0 0] #js [400 200]])
               (.on "brush" (fn [e] (js/console.log "brush" e)))
               (.on "end" (fn [e] (js/console.log "ended brushing" e))))))
would select the body, append an svg with a brush element with listeners etc. However as soon as .append gets called on the selection sci gives an error with:
this.select is not a function [at line 1, column 62]
Which is this source https://github.com/d3/d3-selection/blob/master/src/selection/append.js#L5

bbss05:08:06

I'm wondering what is going wrong, and if there's maybe a config option to fix it.

borkdude06:08:42

@bbss there is a fn? check in interpreter.cljc before the function gets called. Maybe sci is overly protective there. You could try to disable that check. I’m curious what the type of this thing is you are calling.

bbss06:08:29

okay, checking interpreter.cljc

bbss07:08:00

ah, that error message is not the same as "Cannot call x as function"

borkdude07:08:13

Ok, can you do more digging and make a small repro? Could also be a bug in the JS interop code

bbss07:08:15

okay, will do

bbss08:08:18

I was on 0.0.13-alpha.13 , updated to latest git version, fixed some warnings about .- style property access by replacing it for goog.object/get with reader :cljs conditionals in impl/vars.cljc and my problem is gone. Turns out just updating to latest version also works. Those warnings are probably just because I was using :local/root and shadow-cljs warns more strictly for that.

bbss08:08:04

sci remains awesome as ever 🙂

borkdude08:08:38

ok, so no changes needed, also not for the goog.object/get thing?

bbss08:08:25

well, I'm not sure why those warnings started happening, I think a newer version of clojurescript/closure compiler started be more restrictive in property access. But I don't know if that's necessary to fix and if the goog.object/get fix is the way to go. If it comes up for anyone give me a ping and I'll push what fixed it for me. Not much code.