Skip to content

Commit

Permalink
fix: Don't use async when you load files in serie
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
ocombe committed Nov 20, 2014
1 parent 3c066f6 commit 9af93ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 56 deletions.
30 changes: 12 additions & 18 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
el.onerror = function(e) {
deferred.reject(new Error('Unable to load ' + path));
}
el.async = 1;
el.async = params.serie ? 0 : 1;

var insertBeforeElem = anchor.lastChild;
if(params.insertBefore) {
Expand Down Expand Up @@ -225,27 +225,24 @@
* because the user can overwrite templatesLoader and it will probably not use promises :(
*/
templatesLoader = function(paths, callback, params) {
if(angular.isString(paths)) {
paths = [paths];
}
var promises = [];
angular.forEach(paths, function(url) {
var deferred = $q.defer();
promises.push(deferred.promise);
$http.get(url, params).success(function(data) {
angular.forEach(angular.element(data), function(node) {
if(node.nodeName === 'SCRIPT' && node.type === 'text/ng-template') {
$templateCache.put(node.id, node.innerHTML);
}
});
if(angular.isString(data) && data.length > 0) {
angular.forEach(angular.element(data), function(node) {
if(node.nodeName === 'SCRIPT' && node.type === 'text/ng-template') {
$templateCache.put(node.id, node.innerHTML);
}
});
}
if(angular.isUndefined(filesCache.get(url))) {
filesCache.put(url, true);
}
deferred.resolve();
}).error(function(data) {
var err = 'Error load template "' + url + '": ' + data;
$log.error(err);
deferred.reject(new Error(err));
}).error(function(err) {
deferred.reject(new Error('Unable to load template file "' + url + '": ' + err));
});
});
return $q.all(promises).then(function success() {
Expand Down Expand Up @@ -859,13 +856,10 @@
}

function getModuleName(module) {
if(module === null) {
return null;
}
var moduleName = null;
if(typeof module === 'string') {
if(angular.isString(module)) {
moduleName = module;
} else if(typeof module === 'object' && module.hasOwnProperty('name') && typeof module.name === 'string') {
} else if(angular.isObject(module) && module.hasOwnProperty('name') && angular.isString(module.name)) {
moduleName = module.name;
}
return moduleName;
Expand Down
Loading

0 comments on commit 9af93ed

Please sign in to comment.