Fork me on GitHub
#beginners
<
2016-02-20
>
doddenino16:02:26

Ugh, om makes me feel so stupid!

josh.freckleton17:02:27

I'm super stumped, debugging, I've gotten down to this simple line of code that doesn't work as expected under advanced compilation: (js/console.log (.-hey (clj->js {:hey "please work!"}))) prints out undefined any idea what's up?

mfikes18:02:05

@josh.freckleton: I wonder how it would know not to rename .-hey relative to the keyword :hey which won’t be renamed. Interesting.

josh.freckleton18:02:38

Ya, I'm assuming it's a renaming issue, but I have no idea how to deal with it... Thoughts?

mfikes18:02:48

What you wrote isn’t much different than (.-hey #js {"hey" "please work”})

mfikes18:02:03

In other words, you are dynamically creating a need for externs 😕

mfikes18:02:47

@josh.freckleton: If the name “hey” is stable, perhaps externs would solve it.

mfikes18:02:56

Or maybe use a string as the key: (aget #js {"hey" "please work"} "hey”)

josh.freckleton18:02:57

The problem is in some interop with D3. It expects JS objects, which is why I'm using clj->js...

mfikes18:02:38

In terms of your example: (aget (clj->js {:hey "please work!"}) "hey”)

mfikes18:02:16

@josh.freckleton: So, in short :advanced is going to party on the symbol .-hey, but it won’t muck with ”hey”.

mfikes18:02:56

@josh.freckleton: The externs mechanism is designed to deal with this. See, for example https://github.com/federico-b/d3-externs

mfikes18:02:46

Looks like d3 is in cljsjs, which should have all of that nicely bundled together

josh.freckleton18:02:09

Hm, I understand that aget is a little slower, and more meant for accessing dynamically created vars, no? Is there no more-idiomatic way? (and good call on d3 in cljsjs, that's what I'm using :))

mfikes18:02:03

@josh.freckleton: Hmm… gotta run, but that’s what the externs should be doing for you. Unless your symbol .-hey isn’t a stable symbol or somehow not covered in the externs.

josh.freckleton18:02:02

thanks for your help Mike, you've given me enough to probably solve this simple_smile

mfikes18:02:11

@josh.freckleton: It may also make sense to check out :pseudo-names to confirm that it really is a renaming issue: https://github.com/clojure/clojurescript/wiki/Compiler-Options#pseudo-names