Fork me on GitHub

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) { };


that doesn’t look like an externs issue because the name isn’t getting munged


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.


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.


And @oscar the above code works in development.


that’s weird that the typehinting didn’t work. if you use a string accessor it works, I assume?


Yes I'd expect it to work too. What do you mean by a string accessor?


(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.


ooh i missed that this was a direct include


@oscar starting with / has a different meaning in shadow-cljs and means importing from the classpath root.


Ah. I've only ever imported node modules. That makes sense.


@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];


this works. I don't think the issue is solvable by externs alone.


Thanks thheller! I'll give that a go.


That's done it. Thanks, not sure how long it would have taken me to stumble across that. You rock metal


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


oh sorry you were asking a different question


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.

parrot 4
👍 4