This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-26
Channels
- # beginners (17)
- # boot (3)
- # cljs-dev (2)
- # cljsrn (3)
- # clojure (52)
- # clojure-austin (1)
- # clojure-poland (4)
- # clojure-russia (29)
- # clojure-spec (25)
- # clojure-uk (5)
- # clojurescript (39)
- # cursive (29)
- # data-science (5)
- # datomic (5)
- # fulcro (21)
- # graphql (1)
- # hoplon (20)
- # off-topic (5)
- # pedestal (1)
- # perun (3)
- # protorepl (2)
- # re-frame (7)
- # ring (1)
- # shadow-cljs (19)
- # unrepl (10)
- # vim (4)
Is possible require a js
function on cljs
?
I know and I'm using require from npm deps, but when I try to require a "my project js file", compiler warns about "no goog.provide"....
@souenzzo probably the best way to find out is to have a look at the foreign libs feature (https://clojurescript.org/guides/javascript-modules), or at some libraries that make use of it (http://cljsjs.github.io/)
@souenzzo or you could pack your js function in a google closure namespace (in which case you need to do the "goog.provide")
is there a way in clojurescript to iterate over the properties of a javascript object? something equivalent to:
var obj = {prop1: 1, prop2: 2}; for (prop in obj){ if (obj.hasOwnProperty(prop)) {console.log(prop);}}
is using js-invoke
the recommended way to call a js method on a js object that works in advanced opts?
it's for when the name of the method is not syntactically valid
well i tried for example (.someMethod obj arg1 arg2) and the .someMethod is munged. I switched to js-invoke and it works fine
to make sure something works with advanced compilation, you use externs (or one of the new fangled things I don't understand yet)
in my case, the .someMethod is a brower API so its not a library i'm bringing in. yet Closure still munges it, so using js-invoke and the method name as a string literal solved it
externs prevent munging, even with browser apis
well, is there a downside to using js-invoke rather than writing an externs for a browser api?
it's slower than a regular method call, for one thing https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L515
it does a bunch of data transformations you wouldn't otherwise need
combined with the fact that externs are simple to write, and the syntax is much uglier, I would opt for defining an extern
you don't have to dig them up, they are very easy to write
but it is cool that google provides some
well, it's not always obvious what the js class is for a browser api. i can call methods on svg paths for example without knowing the exact JS class needed to write the extern. so digging up that info does take a bit of time
for example i'd have to know its SVGPathElement.prototype.getPointAtLength = function(opt_distance){};
which is not obvious at first
@ajs You can use https://github.com/binaryage/cljs-oops - it doesn't require you to write externs and to know JS classes.
@p-himik any idea why cljs-oops doesn't work on "date-like" objects? https://github.com/binaryage/cljs-oops/blob/585dff172e5f477a2a70a4717571f626a0a3b35e/test/src/tests/oops/main.cljs#L88
@joshkh You should ask the author to get a definitive answer, but I'd say it's because these objects are already perfectly accessible from within CLJS - there's no need for interop.
yes good point, someone explained the other day that core javascript props/functions don't require externs because they're ignored in the closure compiler. still seems odd to specifically rule it out though.
@joshkh You can read more about the issue here: https://github.com/binaryage/cljs-oops/issues/13
what's the CLJS analog for JS libs whose usage requires an import SomeModule from 'some-package'
?
@pandeiro the ES5 equivalent
Thanks @pesterhazy -- I was running into issues related to loading modules in react native, so not actually require/import related
Yeah, don’t forget re-natal use-component
Ah maybe
That’s new