marionettejs / marionette.module Goto Github PK
View Code? Open in Web Editor NEWThe (deprecated) Marionette.Module Class as a standalone library.
License: ISC License
The (deprecated) Marionette.Module Class as a standalone library.
License: ISC License
require('marionette.module').shim(Marionette.Application);
^ That is unnecessary
require('marionette.module');
^ that is all that the API needs to be.
I know I'm late on this, but I'm trying to upgrade my app and I'm still on 2.4. I wanted to use the module shim to make this a bit easier, but if I add the line require('marionette.module').shim(Marionette)
to my app, or even just import Module from 'marionette.module'
then I get the following error:
Uncaught TypeError: Cannot read property 'triggerMethod' of undefined
It points to this code:
// Extend the Module prototype with events / listenTo, so that the module
// can be used as an event aggregator or pub/sub.
_.extend(Module.prototype, Backbone.Events, {
// By default modules start with their parents.
startWithParent: true,
// Initialize is an empty function by default. Override it with your own
// initialization logic when extending Marionette.Module.
initialize: function() {},
// Initializer for a specific module. Initializers are run when the
// module's `start` method is called.
addInitializer: function(callback) {
this._initializerCallbacks.add(callback);
},
// Finalizers are run when a module is stopped. They are used to teardown
// and finalize any variables, references, events and other code that the
// module had set up.
addFinalizer: function(callback) {
this._finalizerCallbacks.add(callback);
},
// Start the module, and run all of its initializers
start: function(options) {
// Prevent re-starting a module that is already started
if (this._isInitialized) { return; }
// start the sub-modules (depth-first hierarchy)
_.each(this.submodules, function(mod) {
// check to see if we should start the sub-module with this parent
if (mod.startWithParent) {
mod.start(options);
}
});
// run the callbacks to "start" the current module
this.triggerMethod('before:start', options);
this._initializerCallbacks.run(options, this);
this._isInitialized = true;
this.triggerMethod('start', options);
},
// Stop this module by running its finalizers and then stop all of
// the sub-modules for this module
stop: function() {
// if we are not initialized, don't bother finalizing
if (!this._isInitialized) { return; }
this._isInitialized = false;
this.triggerMethod('before:stop');
// stop the sub-modules; depth-first, to make sure the
// sub-modules are stopped / finalized before parents
_.invoke(this.submodules, 'stop');
// run the finalizers
this._finalizerCallbacks.run(undefined, this);
// reset the initializers and finalizers
this._initializerCallbacks.reset();
this._finalizerCallbacks.reset();
this.triggerMethod('stop');
},
// Configure the module with a definition function and any custom args
// that are to be passed in to the definition function
addDefinition: function(moduleDefinition, customArgs) {
this._runModuleDefinition(moduleDefinition, customArgs);
},
// Internal method: run the module definition function with the correct
// arguments
_runModuleDefinition: function(definition, customArgs) {
// If there is no definition short circut the method.
if (!definition) { return; }
// build the correct list of arguments for the module definition
// make flattening consistent
// in lodash (v3) it's flatten(collection, deep)
// and in underscore it's flatten(collection, shallow)
var deepFlag = !_.flattenDeep;
var args = _.flatten([
this,
this.app,
Backbone,
Marionette,
Backbone.$, _,
customArgs
], deepFlag);
definition.apply(this, args);
},
// Internal method: set up new copies of initializers and finalizers.
// Calling this method will wipe out all existing initializers and
// finalizers.
_setupInitializersAndFinalizers: function() {
this._initializerCallbacks = new Callbacks();
this._finalizerCallbacks = new Callbacks();
},
// import the `triggerMethod` to trigger events with corresponding
// methods if the method exists
triggerMethod: Marionette.triggerMethod // THIS IS THE LINE THAT THE STACK TRACE STARTS AT
});
Any ideas what is going on here?
If array is provided as additional argument to module definition it gets flattened into separate arguments:
MyApp.module("MyModule", function(MyModule, MyApp, Backbone, Marionette, $, _, arg1, arg2){
// arg1 === 1;
// arg2 === 2;
}, [1, 2]);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.