This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-12
Channels
- # aleph (1)
- # beginners (81)
- # boot (20)
- # cider (46)
- # cljs-dev (6)
- # cljsjs (6)
- # cljsrn (8)
- # clojars (2)
- # clojure (104)
- # clojure-berlin (3)
- # clojure-italy (4)
- # clojure-losangeles (2)
- # clojure-nl (16)
- # clojure-spec (16)
- # clojure-uk (28)
- # clojurescript (88)
- # core-logic (31)
- # cursive (8)
- # data-science (3)
- # datascript (1)
- # datomic (95)
- # docs (1)
- # emacs (6)
- # figwheel-main (24)
- # fulcro (106)
- # graphql (5)
- # hyperfiddle (2)
- # midje (2)
- # nrepl (1)
- # off-topic (14)
- # om-next (1)
- # parinfer (2)
- # pedestal (26)
- # portkey (2)
- # re-frame (11)
- # reagent (27)
- # ring (6)
- # rum (4)
- # shadow-cljs (33)
- # spacemacs (10)
- # specter (53)
- # tools-deps (17)
- # vim (31)
I'm trying to add an extern for an ES6 class ctor in one of my js files. I'm requiring like this:
["/js/audio/wavesurfer.cursor-time" :default wavesurfer-cursor-time-plugin]
The js file looks like:
class CursorTimePlugin {
static create(params) { ... }
}
...
export default CursorTimePlugin;
The runtime error I get when I compile a release build is:
Uncaught TypeError: $module$js$audio$wavesurfer_cursor_time$$.default.create is not a function
Oh and I'm calling the function in my cljs namespace like: (.create ^js wavesurfer-cursor-time-plugin (clj->js (:cursor-time options)))
I've experimented with all sorts of defs in my externs file, but none make the problem go away! For example, the following doesn't work:
var $module$js$audio$wavesurfer_cursor_time$$ = {};
$module$js$audio$wavesurfer_cursor_time$$.default = {};
$module$js$audio$wavesurfer_cursor_time$$.default.create = function(params) { };
if was an advanced compilation issue it would say something like g432 is not a function
@lsnape I think your require string is probably wrong. "/" Means filesystem root. https://nodejs.org/api/modules.html#modules_all_together
Sorry @lee.justin.m should have mentioned I''ve added :pseudo-names
true. If I turn it off then I do indeed get wpa.default.create
is not a function.
that’s weird that the typehinting didn’t work. if you use a string accessor it works, I assume?
(def thing #js{:getSomething (fn [] :a)})
=> #'cljs.user/thing
(goog.object/get thing "getSomething")
=> #object[getSomething]
((goog.object/get thing "getSomething"))
=> :a
you can just use goog.object/get
to grab the create
function off of the imported object and then invoke that value
because the closure compiler does not munge strings, it won’t be subject to advanced compilation
it’s just a way of confirming that the issue is symbol munging rather than the actual create
symbol somehow not being there at all
@lsnape @lee.justin.m this is probably not a munging issue. if you use /js/...
to import the file it will be imported by the closure compiler and passed through :advanced
. meaning it needs to externs.
@oscar starting with /
has a different meaning in shadow-cljs and means importing from the classpath root. https://shadow-cljs.github.io/docs/UsersGuide.html#_requiring_js
@lsnape judging by the compiler output it appears that the static create
method is getting removed by closure. which I believe is documented somewhere. let me see if I can find it
class SomeClass {
/** @nocollapse */
static create(params) {
return ["SomeClass.create",1,2,params];
}
}
That's done it. Thanks, not sure how long it would have taken me to stumble across that. You rock
New shadow-cljs user here. So on shadow-cljs watch app I am getting The required JS dependency "jquery" is not available, it was required by "cljsjs/jquery.cljs".
How can I figure out which dependency needs that so I can assess whether I want it or not?
@dfcarpenter just do a npm i jquery --save
shadow-cljs basically ignores the foreign-libs dependency in the cljsjs package because it reads js code directly from the node_modules
directory, so you need to install the js modules directly
I figured it out by checking each dep repo. Looks like the re-pressed library ( capturing keyboard events in re-frame ) uses jquery ( which is overkill )
i suspect there is a lein deps :tree
type command in the shadow repl but i don’t know what it is
@dfcarpenter Yeah, re-pressed does unfortunately use jQuery 😬 (I didn't want to go through the trouble of making an abstracted way to guarantee cross-browser support ... so leaned on jquery to do it for me with which
)
@gadfly361 Ahh, of course cross browser support. Totally understand; there be dragons for cross browser/legacy browsers. Anyways, does the google closure library not handle this or does it only handle chrome?
@dfcarpenter I am not actually sure, but if it does, then that would be a good approach 🙂
@gadfly361 Actually since gmail and I think the google office suite uses the closure library and it does have really good cross browser support I think it may be a good option.