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#L5I'm wondering what is going wrong, and if there's maybe a config option to fix it.
@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.
okay, checking interpreter.cljc
ah, that error message is not the same as "Cannot call x as function"
Ok, can you do more digging and make a small repro? Could also be a bug in the JS interop code
okay, will do
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.
sci remains awesome as ever š
ok, so no changes needed, also not for the goog.object/get
thing?
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.