MDL-63667 javascript: fix failed to pre-fetch the template error
This commit is contained in:
committed by
Damyon Wiese
parent
c2f1dbcf49
commit
0015f5b8f1
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+17
-12
@@ -50,6 +50,9 @@ define(['core/mustache',
|
||||
/** @var {Promise[]} templatePromises - Cache of already loaded template promises */
|
||||
var templatePromises = {};
|
||||
|
||||
/** @var {Promise[]} cachePartialPromises - Cache of already loaded template partial promises */
|
||||
var cachePartialPromises = {};
|
||||
|
||||
/** @var {Object} iconSystem - Object extending core/iconsystem */
|
||||
var iconSystem = {};
|
||||
|
||||
@@ -648,24 +651,26 @@ define(['core/mustache',
|
||||
* @return {Promise} JQuery promise object resolved when all partials are in the cache.
|
||||
*/
|
||||
Renderer.prototype.cachePartials = function(templateName) {
|
||||
return this.getTemplate(templateName).then(function(templateSource) {
|
||||
var i;
|
||||
var partials = this.scanForPartials(templateSource);
|
||||
var fetchThemAll = [];
|
||||
var searchKey = this.currentThemeName + '/' + templateName;
|
||||
|
||||
for (i = 0; i < partials.length; i++) {
|
||||
var searchKey = this.currentThemeName + '/' + partials[i];
|
||||
if (searchKey in templatePromises) {
|
||||
fetchThemAll.push(templatePromises[searchKey]);
|
||||
} else {
|
||||
fetchThemAll.push(this.cachePartials(partials[i]));
|
||||
}
|
||||
}
|
||||
if (searchKey in cachePartialPromises) {
|
||||
return cachePartialPromises[searchKey];
|
||||
}
|
||||
|
||||
var cachePartialPromise = this.getTemplate(templateName).then(function(templateSource) {
|
||||
var partials = this.scanForPartials(templateSource);
|
||||
var fetchThemAll = partials.map(function(partialName) {
|
||||
return this.cachePartials(partialName);
|
||||
}.bind(this));
|
||||
|
||||
return $.when.apply($, fetchThemAll).then(function() {
|
||||
return templateSource;
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
cachePartialPromises[searchKey] = cachePartialPromise;
|
||||
|
||||
return cachePartialPromise;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user