Fork me on GitHub
#luminus
<
2017-01-06
>
mbcev14:01:55

Another ridiculously simple question, how do I reference a JS function for example say in my "public/js/myCode.js" in my CLJS core? (myFunction args) doesn't resolve.

manutter5115:01:35

@mbcev are you loading myCode.js in a script tag in your index page?

manutter5115:01:35

or home.html rather. There’s this bit at the bottom of resources/templates/home.html:

manutter5115:01:25

I’m guessing you just need {% script “/js/myCode.js" %} above the line that says {% script "/js/app.js" %}

mbcev15:01:42

I have {% script "/js/myCode.js" %} in my base.html and when I add a myFunction("args); call to it, it does in fact run but my core.cljs still doesn't see it.

mbcev15:01:13

This doesn't have anything to do with namespaces right? If I include that function call to base it's part of the global namespace so I would just say (myFunction args) in CLJS and not like (myCode/myFunction args) or something

manutter5115:01:32

Right, if it’s a straight JS function, namespaces don’t apply

manutter5115:01:50

You should be able to call it with (js/myFunction args)

manutter5115:01:23

The js/ prefix is required for interop

mbcev15:01:26

When I was googling around I saw something about externs for including straight JS libraries? That's overkill for what I'm trying to achieve right?

manutter5115:01:42

Hmm, you probably do need externs actually

manutter5115:01:11

Otherwise when your cljs code calls (js/myFunction args) it might get turned into (js/jz args) or some such

mbcev15:01:15

when I make changes to my project.clj I have to restart the repl right? (That's what I'm waiting on right now to see if adding the "resources/public/js/charts.js" path to :externs fixed it)

mbcev15:01:41

No dice; but I just found cljsjs/dygraph (dygraph.js is ultimately what I'm trying to work with) so I'll see if I can't just re-write my charts in native cljs rather than referencing them as pure JS functions

mbcev16:01:43

oh also @manutter51 thanks for the help; just found I had a bug else where that was causing (js/myFunction args) to not run. Externs aren't needed, just the {%script %} reference in base.html (or wherever)

yogthos17:01:12

I recommend checking cljsjs as well http://cljsjs.github.io/ before using externs

yogthos17:01:10

if the library is packaged there, then you just have to include it as a dependency and require it in one of the namespaces

yogthos17:01:22

when you do use externs, you should be able to give the library js as the source for the externs in most cases

mbcev17:01:53

Awesome, thanks guys.