Upgrade templates when performing the CustomElements treewalk

This calls `querySelectorAll` way less frequently while still upgrading
templates before custom elements upgrade.

`HTMLTemplateElement.decorate` will now bootstrap the template content, so
Polymer can use `decorate` when it preps the template for data binding.
This commit is contained in:
Daniel Freedman 2015-11-16 12:09:19 -08:00
Родитель 7297a08ed1
Коммит ef67dec211
4 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -306,18 +306,12 @@ if (originalCreateShadowRoot) {
};
}
function upgradeAll(doc) {
if (HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
HTMLTemplateElement.bootstrap(doc);
}
addedNode(doc);
}
// exports
scope.watchShadow = watchShadow;
scope.upgradeDocumentTree = upgradeDocumentTree;
scope.upgradeDocument = upgradeDocument;
scope.upgradeSubtree = addedSubtree;
scope.upgradeAll = upgradeAll;
scope.upgradeAll = addedNode;
scope.attached = attached;
scope.takeRecords = takeRecords;

Просмотреть файл

@ -33,6 +33,12 @@ var flags = scope.flags;
*/
// Upgrade a node if it can be upgraded and is not already.
function upgrade(node, isAttached) {
// upgrade template elements before custom elements
if (node.localName === 'template') {
if (window.HTMLTemplateElement && HTMLTemplateElement.decorate) {
HTMLTemplateElement.decorate(node);
}
}
if (!node.__upgraded__ && (node.nodeType === Node.ELEMENT_NODE)) {
var is = node.getAttribute('is');
// find definition first by localName and secondarily by is attribute

Просмотреть файл

@ -28,9 +28,11 @@ if (typeof HTMLTemplateElement === 'undefined') {
NOTE: there is no support for dynamically adding elements to templates.
*/
HTMLTemplateElement.decorate = function(template) {
if (!template.content) {
template.content = contentDoc.createDocumentFragment();
// if the template is decorated, return fast
if (template.content) {
return;
}
template.content = contentDoc.createDocumentFragment();
var child;
while (child = template.firstChild) {
template.content.appendChild(child);
@ -63,6 +65,9 @@ if (typeof HTMLTemplateElement === 'undefined') {
canDecorate = false;
}
}
// bootstrap recursively
HTMLTemplateElement.bootstrap(template.content);
};
/**

Просмотреть файл

@ -1,3 +1,6 @@
{
"suites": ["tests/runner.html"]
"suites": ["tests/runner.html"],
"clientOptions": {
"environmentImports": []
}
}