Skip to content

Commit

Permalink
Merge pull request #42 from BenBlazely/master
Browse files Browse the repository at this point in the history
fix: prevent duplicate loadings

Fixes #35
Fixes #38
  • Loading branch information
ocombe committed Jul 22, 2014
2 parents 2aad734 + d737f1e commit 12bc6b2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@

angular.forEach(paths, function(path) {
if(angular.isUndefined(filesCache.get(path)) || params.cache === false) {
if(/\.css[^\.]*$/.test(path)) {
if(/\.css[^\.]*$/.test(path) && cssFiles.indexOf(path) === -1) {
cssFiles.push(path);
} else if(/\.(htm|html)[^\.]*$/.test(path)) {
} else if(/\.(htm|html)[^\.]*$/.test(path) && templatesFiles.indexOf(path) === -1) {
templatesFiles.push(path);
} else {
} else if (/\.(js)[^\.]*$/.test(path) && jsFiles.indexOf(path) === -1) {
jsFiles.push(path);
}
}
Expand Down Expand Up @@ -288,7 +288,9 @@
if(angular.isArray(module)) {
// Resubmit each entry as a single module
angular.forEach(module, function(m) {
deferredList.push(self.load(m, params));
if (m) {
deferredList.push(self.load(m, params));
}
});

// Resolve the promise once everything has loaded
Expand Down Expand Up @@ -353,6 +355,7 @@
var moduleName,
loadedModule,
requires,
diff,
promisesList = [];

moduleName = getModuleName(module);
Expand Down Expand Up @@ -385,10 +388,17 @@
// Check if this dependency has been loaded previously or is already in the moduleCache
if(moduleExists(requireEntry.name) || moduleCache.indexOf(requireEntry.name) !== -1) {
if(typeof module !== 'string') {
// The dependency exists, but it's being redefined, not inherited by a simple string reference, raise a warning and ignore the new config.
// TODO: This could be made smarter. There's no checking here yet to determine if the configurations are actually different.
$log.warn('Module "', moduleName, '" attempted to redefine configuration for dependency "', requireEntry.name, '"\nExisting:', self.getModuleConfig(requireEntry.name), 'Ignored:', requireEntry);
}
// compare against the already loaded module to see if the new definition adds any new files
diff = requireEntry.files.filter(function (n) {
return self.getModuleConfig(requireEntry.name).files.indexOf(n) < 0
});
if (diff.length !== 0) {
$log.warn('Module "', moduleName, '" attempted to redefine configuration for dependency. "', requireEntry.name, '"\n Additional Files Loaded:', diff);
promisesList.push(filesLoader(diff, params).then(function () {
return loadDependencies(requireEntry);
}));
}
}
return;
} else if(typeof requireEntry === 'object') {
if(requireEntry.hasOwnProperty('name') && requireEntry['name']) {
Expand All @@ -401,7 +411,7 @@
if(requireEntry.hasOwnProperty('css') && requireEntry['css'].length !== 0) {
// Locate the document insertion point
angular.forEach(requireEntry['css'], function(path) {
buildElement('css', path);
buildElement('css', path, params);
});
}
// CSS End.
Expand Down

0 comments on commit 12bc6b2

Please sign in to comment.