Extending custom module from custom module via plugin manager

I’m trying to write a module that extends another one.

I can grab the instance, from _this.embedPlayer.plugins.otherModule, but it takes a while to initialize and I get undefined errors.

If I grab the instance during the onSelectSource event, I’m good to go but it doesn’t seem the right way and I’d rather get everything set up in the setup method.

Is there a load order? Or a load sequence I can manipulate?
Wouldn’t mw.PluginManager.get( ‘otherModule’ ) be a good method to have for this purpose?

I’d rather stick to the DRY principal and not include the library again in my other module if possible but if that’s the right way, I’m happy to do it.

If you need to extend the behviour of a plugin, or override it you need to do it in the following way:

mw.PluginManager.add('myExtendedModule', mw.PluginManager.getClass("otherModule").extend({
    //you can override any method of the otherModule you are extending in here
    //or add your own logic, like event listeners and call the otherModule methods directly
}));

You need to remember not to include the otherModule in the available modules in your player and set only the myExtendedModule as enabled, otherwise both plugins will be initiated in your player, and it will probably yield unwanted results.

Great, thanks! I’ll give it a go.