Skip to content

Commit

Permalink
fix: don't try to call angular.module on config names
Browse files Browse the repository at this point in the history
Fixes #217
Fixes #218
  • Loading branch information
ocombe committed Jul 30, 2015
1 parent c64e98e commit 52219f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
21 changes: 13 additions & 8 deletions dist/modules/ocLazyLoad.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
regInvokes = {},
regConfigs = [],
modulesToLoad = [],
recordDeclarations = [],
// modules to load from angular.module or other sources
realModules = [],
// real modules called from angular.module
recordDeclarations = [],
broadcast = angular.noop,
runBlocks = {},
justLoaded = [];
Expand Down Expand Up @@ -167,14 +170,13 @@
if (!angular.isString(moduleName)) {
moduleName = getModuleName(moduleName);
}
if (!moduleName || justLoaded.indexOf(moduleName) !== -1) {
if (!moduleName || justLoaded.indexOf(moduleName) !== -1 || realModules.indexOf(moduleName) === -1) {
continue;
}
// new if not registered, and not a config name
var newModule = regModules.indexOf(moduleName) === -1 && !modules[moduleName];
// new if not registered
var newModule = regModules.indexOf(moduleName) === -1;
moduleFn = ngModuleFct(moduleName);
if (newModule) {
// new module
regModules.push(moduleName);
_register(providers, moduleFn.requires, params);
}
Expand Down Expand Up @@ -700,20 +702,23 @@
angular.bootstrap = function (element, modules, config) {
// we use slice to make a clean copy
angular.forEach(modules.slice(), function (module) {
_addToLoadList(module, true);
_addToLoadList(module, true, true);
});
return bootstrapFct(element, modules, config);
};

var _addToLoadList = function _addToLoadList(name, force) {
var _addToLoadList = function _addToLoadList(name, force, real) {
if ((recordDeclarations.length > 0 || force) && angular.isString(name) && modulesToLoad.indexOf(name) === -1) {
modulesToLoad.push(name);
if (real) {
realModules.push(name);
}
}
};

var ngModuleFct = angular.module;
angular.module = function (name, requires, configFn) {
_addToLoadList(name);
_addToLoadList(name, false, true);
return ngModuleFct(name, requires, configFn);
};

Expand Down
21 changes: 13 additions & 8 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
regInvokes = {},
regConfigs = [],
modulesToLoad = [],
recordDeclarations = [],
// modules to load from angular.module or other sources
realModules = [],
// real modules called from angular.module
recordDeclarations = [],
broadcast = angular.noop,
runBlocks = {},
justLoaded = [];
Expand Down Expand Up @@ -174,14 +177,13 @@
if (!angular.isString(moduleName)) {
moduleName = getModuleName(moduleName);
}
if (!moduleName || justLoaded.indexOf(moduleName) !== -1) {
if (!moduleName || justLoaded.indexOf(moduleName) !== -1 || realModules.indexOf(moduleName) === -1) {
continue;
}
// new if not registered, and not a config name
var newModule = regModules.indexOf(moduleName) === -1 && !modules[moduleName];
// new if not registered
var newModule = regModules.indexOf(moduleName) === -1;
moduleFn = ngModuleFct(moduleName);
if (newModule) {
// new module
regModules.push(moduleName);
_register(providers, moduleFn.requires, params);
}
Expand Down Expand Up @@ -707,20 +709,23 @@
angular.bootstrap = function (element, modules, config) {
// we use slice to make a clean copy
angular.forEach(modules.slice(), function (module) {
_addToLoadList(module, true);
_addToLoadList(module, true, true);
});
return bootstrapFct(element, modules, config);
};

var _addToLoadList = function _addToLoadList(name, force) {
var _addToLoadList = function _addToLoadList(name, force, real) {
if ((recordDeclarations.length > 0 || force) && angular.isString(name) && modulesToLoad.indexOf(name) === -1) {
modulesToLoad.push(name);
if (real) {
realModules.push(name);
}
}
};

var ngModuleFct = angular.module;
angular.module = function (name, requires, configFn) {
_addToLoadList(name);
_addToLoadList(name, false, true);
return ngModuleFct(name, requires, configFn);
};

Expand Down
2 changes: 1 addition & 1 deletion dist/ocLazyLoad.min.js

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions dist/ocLazyLoad.require.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
regInvokes = {},
regConfigs = [],
modulesToLoad = [],
recordDeclarations = [],
// modules to load from angular.module or other sources
realModules = [],
// real modules called from angular.module
recordDeclarations = [],
broadcast = angular.noop,
runBlocks = {},
justLoaded = [];
Expand Down Expand Up @@ -174,14 +177,13 @@
if (!angular.isString(moduleName)) {
moduleName = getModuleName(moduleName);
}
if (!moduleName || justLoaded.indexOf(moduleName) !== -1) {
if (!moduleName || justLoaded.indexOf(moduleName) !== -1 || realModules.indexOf(moduleName) === -1) {
continue;
}
// new if not registered, and not a config name
var newModule = regModules.indexOf(moduleName) === -1 && !modules[moduleName];
// new if not registered
var newModule = regModules.indexOf(moduleName) === -1;
moduleFn = ngModuleFct(moduleName);
if (newModule) {
// new module
regModules.push(moduleName);
_register(providers, moduleFn.requires, params);
}
Expand Down Expand Up @@ -707,20 +709,23 @@
angular.bootstrap = function (element, modules, config) {
// we use slice to make a clean copy
angular.forEach(modules.slice(), function (module) {
_addToLoadList(module, true);
_addToLoadList(module, true, true);
});
return bootstrapFct(element, modules, config);
};

var _addToLoadList = function _addToLoadList(name, force) {
var _addToLoadList = function _addToLoadList(name, force, real) {
if ((recordDeclarations.length > 0 || force) && angular.isString(name) && modulesToLoad.indexOf(name) === -1) {
modulesToLoad.push(name);
if (real) {
realModules.push(name);
}
}
};

var ngModuleFct = angular.module;
angular.module = function (name, requires, configFn) {
_addToLoadList(name);
_addToLoadList(name, false, true);
return ngModuleFct(name, requires, configFn);
};

Expand Down
Loading

0 comments on commit 52219f9

Please sign in to comment.