Skip to content

Commit

Permalink
Merge branch 'MDL-63667-34-fix2' of git://github.com/damyon/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_34_STABLE
  • Loading branch information
junpataleta committed Oct 18, 2018
2 parents be3a6f8 + 0ede37a commit 6871e90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/templates.min.js

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

35 changes: 27 additions & 8 deletions lib/amd/src/templates.js
Expand Up @@ -657,20 +657,39 @@ define(['core/mustache',
return cachePartialPromises[searchKey];
}

var cachePartialPromise = this.getTemplate(templateName).then(function(templateSource) {
// This promise will not be resolved until all child partials are also resolved and ready.
// We create it here to allow us to check for recursive inclusion of templates.
cachePartialPromises[searchKey] = $.Deferred();

this.getTemplate(templateName)
.then(function(templateSource) {
var partials = this.scanForPartials(templateSource);
var fetchThemAll = partials.map(function(partialName) {
var uniquePartials = partials.filter(function(partialName) {
// Check for recursion.

if (typeof cachePartialPromises[this.currentThemeName + '/' + partialName] !== 'undefined') {
// Ignore templates which include their parent.
return false;
}

// Ignore templates that include themselves.
return partialName != templateName;
}.bind(this));

// Fetch any partial which has not already been fetched.
var fetchThemAll = uniquePartials.map(function(partialName) {
return this.cachePartials(partialName);
}.bind(this));

return $.when.apply($, fetchThemAll).then(function() {
return templateSource;
// Resolve the templateName promise when all of the children are resolved.
return $.when.apply($, fetchThemAll)
.then(function() {
return cachePartialPromises[searchKey].resolve(templateSource);
});
}.bind(this));

cachePartialPromises[searchKey] = cachePartialPromise;
}.bind(this))
.catch(cachePartialPromises[searchKey].reject);

return cachePartialPromise;
return cachePartialPromises[searchKey];
};

/**
Expand Down

0 comments on commit 6871e90

Please sign in to comment.