Skip to content

Commit

Permalink
fix: files cache should be cleaned upon resolution of the promise
Browse files Browse the repository at this point in the history
Fixes #189
  • Loading branch information
ocombe committed May 29, 2015
1 parent 3159547 commit 9a186c9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions dist/modules/ocLazyLoad.loaders.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
el.src = params.cache === false ? cacheBuster(path) : path;
break;
default:
filesCache.remove(path);
deferred.reject(new Error("Requested type \"" + type + "\" is not known. Could not inject \"" + path + "\""));
break;
}
Expand All @@ -59,9 +60,11 @@
el.onload = el.onreadystatechange = null;
loaded = 1;
$delegate._broadcast("ocLazyLoad.fileLoaded", path);
filesCache.remove(path);
deferred.resolve();
};
el.onerror = function () {
filesCache.remove(path);
deferred.reject(new Error("Unable to load " + path));
};
el.async = params.serie ? 0 : 1;
Expand Down
3 changes: 3 additions & 0 deletions dist/ocLazyLoad.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ocLazyLoad.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/ocLazyLoad.require.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ocLazyLoad.require.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ocLazyLoad.require.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/ocLazyLoad.loaders.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@
el.src = params.cache === false ? cacheBuster(path) : path;
break;
default:
deferred.reject(new Error(`Requested type "${ type }" is not known. Could not inject "${ path }"`));
filesCache.remove(path);
deferred.reject(new Error(`Requested type "${ type }" is not known. Could not inject "${ path }"`));
break;
}
el.onload = el['onreadystatechange'] = function(e) {
if((el['readyState'] && !/^c|loade/.test(el['readyState'])) || loaded) return;
el.onload = el['onreadystatechange'] = null;
loaded = 1;
$delegate._broadcast('ocLazyLoad.fileLoaded', path);
filesCache.remove(path);
deferred.resolve();
};
el.onerror = function() {
filesCache.remove(path);
deferred.reject(new Error(`Unable to load ${ path }`));
};
el.async = params.serie ? 0 : 1;
Expand Down

0 comments on commit 9a186c9

Please sign in to comment.