Skip to content

Commit

Permalink
fix: keep global params pristine when loading files
Browse files Browse the repository at this point in the history
Fixes #89
  • Loading branch information
ocombe committed Nov 9, 2014
1 parent af2627b commit 6b2306b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
21 changes: 11 additions & 10 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,14 @@
templatesFiles = [],
jsFiles = [],
promises = [],
cachePromise = null;
cachePromise = null,
localParams = {};

angular.extend(params || {}, config);
angular.extend(localParams, params || {}, config);

var pushFile = function(path) {
cachePromise = filesCache.get(path);
if(angular.isUndefined(cachePromise) || params.cache === false) {
if(angular.isUndefined(cachePromise) || localParams.cache === false) {
if(/\.css[^\.]*$/.test(path) && cssFiles.indexOf(path) === -1) {
cssFiles.push(path);
} else if(/\.(htm|html)[^\.]*$/.test(path) && templatesFiles.indexOf(path) === -1) {
Expand All @@ -273,10 +274,10 @@
}
}

if(params.serie) {
pushFile(params.files.shift());
if(localParams.serie) {
pushFile(localParams.files.shift());
} else {
angular.forEach(params.files, function(path) {
angular.forEach(localParams.files, function(path) {
pushFile(path);
});
}
Expand All @@ -290,7 +291,7 @@
} else {
cssDeferred.resolve();
}
}, params);
}, localParams);
promises.push(cssDeferred.promise);
}

Expand All @@ -303,7 +304,7 @@
} else {
templatesDeferred.resolve();
}
}, params);
}, localParams);
promises.push(templatesDeferred.promise);
}

Expand All @@ -316,11 +317,11 @@
} else {
jsDeferred.resolve();
}
}, params);
}, localParams);
promises.push(jsDeferred.promise);
}

if(params.serie && params.files.length > 0) {
if(localParams.serie && localParams.files.length > 0) {
return $q.all(promises).then(function success() {
return filesLoader(config, params);
});
Expand Down
Loading

0 comments on commit 6b2306b

Please sign in to comment.