MDL-63667 javascript: fix failed to pre-fetch the template error

This commit is contained in:
Ryan Wyllie 2018-10-16 11:25:19 +08:00 committed by Damyon Wiese
parent c2f1dbcf49
commit 0015f5b8f1
2 changed files with 18 additions and 13 deletions

File diff suppressed because one or more lines are too long

View file

@ -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;
};
/**