marionette-rails 1.0.0.beta4 → 1.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Backbone.Marionette, v1.0.0-beta4
2
+ * Backbone.Marionette, v1.0.0-beta5
3
3
  * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
4
4
  * Distributed under MIT license
5
5
  * http://github.com/marionettejs/backbone.marionette
@@ -1734,21 +1734,27 @@ _.extend(Marionette.Module, {
1734
1734
  var length = moduleNames.length;
1735
1735
  _.each(moduleNames, function(moduleName, i){
1736
1736
  var isLastModuleInChain = (i === length-1);
1737
-
1737
+ var isFirstModuleInChain = (i === 0);
1738
1738
  var module = that._getModuleDefinition(parentModule, moduleName, app);
1739
- module.config.options = that._getModuleOptions(parentModule, moduleDefinition);
1740
1739
 
1741
- // if it's the first module in the chain, configure it
1742
- // for auto-start, as specified by the options
1740
+ // if this is the last module in the chain, then set up
1741
+ // all of the module options from the configuration
1743
1742
  if (isLastModuleInChain){
1744
- that._configureAutoStart(app, module);
1743
+ module.config.options = that._getModuleOptions(module, parentModule, moduleDefinition);
1744
+
1745
+ // Only add a module definition and initializer when this is the last
1746
+ // module in a "parent.child.grandchild" hierarchy of module names and
1747
+ // when the module call has a definition function supplied
1748
+ if (module.config.options.hasDefinition){
1749
+ module.addDefinition(module.config.options.definition, customArgs);
1750
+ }
1745
1751
  }
1746
1752
 
1747
- // Only add a module definition and initializer when this is
1748
- // the last module in a "parent.child.grandchild" hierarchy of
1749
- // module names
1750
- if (isLastModuleInChain && module.config.options.hasDefinition){
1751
- module.addDefinition(module.config.options.definition, customArgs);
1753
+ // if it's a top level module, and this is the only
1754
+ // module in the chain, then this one gets configured
1755
+ // to start with the parent app.
1756
+ if (isFirstModuleInChain && isLastModuleInChain ){
1757
+ that._configureStartWithApp(app, module);
1752
1758
  }
1753
1759
 
1754
1760
  // Reset the parent module so that the next child
@@ -1760,20 +1766,26 @@ _.extend(Marionette.Module, {
1760
1766
  return parentModule;
1761
1767
  },
1762
1768
 
1763
- _configureAutoStart: function(app, module){
1764
- // Only add the initializer if it's the first module, and
1765
- // if it is set to auto-start, and if it has not yet been added
1766
- if (module.config.options.startWithParent && !module.config.autoStartConfigured){
1767
- // start the module when the app starts
1768
- app.addInitializer(function(options){
1769
- module.start(options);
1770
- });
1769
+ // Only add the initializer if it is set to start with parent (the app),
1770
+ // and if it has not yet been added
1771
+ _configureStartWithApp: function(app, module){
1772
+ // skip this if we have already configured the module to start w/ the app
1773
+ if (module.config.startWithAppIsConfigured){
1774
+ return;
1771
1775
  }
1776
+
1777
+ // start the module when the app starts
1778
+ app.addInitializer(function(options){
1779
+ // but only if the module is configured to start w/ parent
1780
+ if (module.config.options.startWithParent){
1781
+ module.start(options);
1782
+ }
1783
+ });
1772
1784
 
1773
1785
  // prevent this module from being configured for
1774
1786
  // auto start again. the first time the module
1775
1787
  // is defined, determines it's auto-start
1776
- module.config.autoStartConfigured = true;
1788
+ module.config.startWithAppIsConfigured = true;
1777
1789
  },
1778
1790
 
1779
1791
  _getModuleDefinition: function(parentModule, moduleName, app){
@@ -1791,10 +1803,16 @@ _.extend(Marionette.Module, {
1791
1803
  return module;
1792
1804
  },
1793
1805
 
1794
- _getModuleOptions: function(parentModule, moduleDefinition){
1795
- // default to starting the module with the app
1806
+ _getModuleOptions: function(module, parentModule, moduleDefinition){
1807
+ // default to starting the module with it's parent to whatever the
1808
+ var startWithParent = true;
1809
+ if (module.config.options && !module.config.options.startWithParent){
1810
+ startWithParent = false;
1811
+ }
1812
+
1813
+ // set up initial options for the module
1796
1814
  var options = {
1797
- startWithParent: true,
1815
+ startWithParent: startWithParent,
1798
1816
  hasDefinition: !!moduleDefinition
1799
1817
  };
1800
1818
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marionette-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: