Skip to content

Commit

Permalink
Fixed duplication of script requests due to a race condition while lo…
Browse files Browse the repository at this point in the history
…ading dependencies.
  • Loading branch information
Meesayen committed Sep 21, 2015
1 parent f25b6e9 commit 9b2aed0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function normalizeName(child, parentBase) {
}

var seen = Object.create(null);
var pendingPromises = Object.create(null);
var internalRegistry = Object.create(null);
var externalRegistry = Object.create(null);
var anonymousEntry;
Expand Down Expand Up @@ -74,7 +75,10 @@ function createScriptNode(src, callback) {
}

function load(name) {
return new Promise(function(resolve, reject) {
if (pendingPromises[name]) {
return pendingPromises[name];
}
pendingPromises[name] = new Promise(function(resolve, reject) {
createScriptNode((System.baseURL || '/') + name + '.js', function(err) {
if (anonymousEntry) {
System.register(name, anonymousEntry[0], anonymousEntry[1]);
Expand All @@ -93,6 +97,7 @@ function load(name) {
})).then(resolve, reject);
});
});
return pendingPromises[name];
}


Expand Down
7 changes: 6 additions & 1 deletion dist/system-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function normalizeName(child, parentBase) {
}

var seen = Object.create(null);
var pendingPromises = Object.create(null);
var internalRegistry = Object.create(null);
var externalRegistry = Object.create(null);
var anonymousEntry;
Expand Down Expand Up @@ -74,7 +75,10 @@ function createScriptNode(src, callback) {
}

function load(name) {
return new Promise(function(resolve, reject) {
if (pendingPromises[name]) {
return pendingPromises[name];
}
pendingPromises[name] = new Promise(function(resolve, reject) {
createScriptNode((System.baseURL || '/') + name + '.js', function(err) {
if (anonymousEntry) {
System.register(name, anonymousEntry[0], anonymousEntry[1]);
Expand All @@ -93,6 +97,7 @@ function load(name) {
})).then(resolve, reject);
});
});
return pendingPromises[name];
}


Expand Down
2 changes: 1 addition & 1 deletion dist/system-polyfill.min.js

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

0 comments on commit 9b2aed0

Please sign in to comment.