Giter Site home page Giter Site logo

marionette.module's People

Contributors

jamesplease avatar paulfalgout avatar samccone avatar stalmok avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

axelbox

marionette.module's Issues

Patch Application directly

require('marionette.module').shim(Marionette.Application);

^ That is unnecessary

require('marionette.module');

^ that is all that the API needs to be.

Importing 'marionette.module' causes an error in the Marionette 3.0 build

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.