This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-06
Channels
- # architecture (8)
- # aws (2)
- # beginners (156)
- # boot (163)
- # cider (22)
- # cljs-dev (2)
- # cljsrn (11)
- # clojars (6)
- # clojure (328)
- # clojure-austin (7)
- # clojure-dusseldorf (10)
- # clojure-italy (2)
- # clojure-russia (19)
- # clojure-spec (178)
- # clojure-uk (86)
- # clojurescript (81)
- # cursive (17)
- # datomic (33)
- # funcool (40)
- # hoplon (8)
- # jobs (5)
- # klipse (13)
- # leiningen (1)
- # luminus (21)
- # off-topic (140)
- # om (49)
- # om-next (4)
- # onyx (29)
- # planck (5)
- # protorepl (2)
- # re-frame (58)
- # reagent (2)
- # remote-jobs (4)
- # ring-swagger (16)
- # testing (1)
- # untangled (26)
- # yada (27)
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.
@mbcev are you loading myCode.js in a script tag in your index page?
or home.html rather. There’s this bit at the bottom of resources/templates/home.html
:
I’m guessing you just need {% script “/js/myCode.js" %}
above the line that says {% script "/js/app.js" %}
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.
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
Right, if it’s a straight JS function, namespaces don’t apply
You should be able to call it with (js/myFunction args)
The js/
prefix is required for interop
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?
Hmm, you probably do need externs actually
Otherwise when your cljs code calls (js/myFunction args) it might get turned into (js/jz args) or some such
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)
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
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)
I recommend checking cljsjs as well http://cljsjs.github.io/ before using externs
if the library is packaged there, then you just have to include it as a dependency and require it in one of the namespaces
when you do use externs, you should be able to give the library js as the source for the externs in most cases