mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: guard against concurrent loading of deferred assets
This commit is contained in:
parent
de3e48c16e
commit
ada7b4a4e8
1 changed files with 12 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
/* global assetPath */
|
/* global assetPath */
|
||||||
|
|
||||||
const _loaded = {};
|
const _loaded = {};
|
||||||
|
const _loading = {};
|
||||||
|
|
||||||
function loadWithTag(path, cb) {
|
function loadWithTag(path, cb) {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const head = document.getElementsByTagName('head')[0];
|
||||||
|
@ -29,9 +30,20 @@ export default function loadScript(url, opts) {
|
||||||
|
|
||||||
// If we already loaded this url
|
// If we already loaded this url
|
||||||
if (_loaded[url]) { return resolve(); }
|
if (_loaded[url]) { return resolve(); }
|
||||||
|
if (_loading[url]) { return _loading[url].then(resolve);}
|
||||||
|
|
||||||
|
var done;
|
||||||
|
_loading[url] = new Ember.RSVP.Promise(function(_done){
|
||||||
|
done = _done;
|
||||||
|
});
|
||||||
|
|
||||||
|
_loading[url].then(function(){
|
||||||
|
delete _loading[url];
|
||||||
|
});
|
||||||
|
|
||||||
const cb = function() {
|
const cb = function() {
|
||||||
_loaded[url] = true;
|
_loaded[url] = true;
|
||||||
|
done();
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue