mirror of
https://github.com/jlengrand/webcomponentsjs.git
synced 2026-03-10 08:51:22 +00:00
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:
@@ -306,18 +306,12 @@ if (originalCreateShadowRoot) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgradeAll(doc) {
|
|
||||||
if (HTMLTemplateElement && HTMLTemplateElement.bootstrap) {
|
|
||||||
HTMLTemplateElement.bootstrap(doc);
|
|
||||||
}
|
|
||||||
addedNode(doc);
|
|
||||||
}
|
|
||||||
// exports
|
// exports
|
||||||
scope.watchShadow = watchShadow;
|
scope.watchShadow = watchShadow;
|
||||||
scope.upgradeDocumentTree = upgradeDocumentTree;
|
scope.upgradeDocumentTree = upgradeDocumentTree;
|
||||||
scope.upgradeDocument = upgradeDocument;
|
scope.upgradeDocument = upgradeDocument;
|
||||||
scope.upgradeSubtree = addedSubtree;
|
scope.upgradeSubtree = addedSubtree;
|
||||||
scope.upgradeAll = upgradeAll;
|
scope.upgradeAll = addedNode;
|
||||||
scope.attached = attached;
|
scope.attached = attached;
|
||||||
scope.takeRecords = takeRecords;
|
scope.takeRecords = takeRecords;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ var flags = scope.flags;
|
|||||||
*/
|
*/
|
||||||
// Upgrade a node if it can be upgraded and is not already.
|
// Upgrade a node if it can be upgraded and is not already.
|
||||||
function upgrade(node, isAttached) {
|
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)) {
|
if (!node.__upgraded__ && (node.nodeType === Node.ELEMENT_NODE)) {
|
||||||
var is = node.getAttribute('is');
|
var is = node.getAttribute('is');
|
||||||
// find definition first by localName and secondarily by is attribute
|
// 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.
|
NOTE: there is no support for dynamically adding elements to templates.
|
||||||
*/
|
*/
|
||||||
HTMLTemplateElement.decorate = function(template) {
|
HTMLTemplateElement.decorate = function(template) {
|
||||||
if (!template.content) {
|
// if the template is decorated, return fast
|
||||||
template.content = contentDoc.createDocumentFragment();
|
if (template.content) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
template.content = contentDoc.createDocumentFragment();
|
||||||
var child;
|
var child;
|
||||||
while (child = template.firstChild) {
|
while (child = template.firstChild) {
|
||||||
template.content.appendChild(child);
|
template.content.appendChild(child);
|
||||||
@@ -63,6 +65,9 @@ if (typeof HTMLTemplateElement === 'undefined') {
|
|||||||
canDecorate = false;
|
canDecorate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bootstrap recursively
|
||||||
|
HTMLTemplateElement.bootstrap(template.content);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"suites": ["tests/runner.html"]
|
"suites": ["tests/runner.html"],
|
||||||
|
"clientOptions": {
|
||||||
|
"environmentImports": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user