diff --git a/src/TemplateBinding.js b/src/TemplateBinding.js index 7bf657d..9a42a13 100644 --- a/src/TemplateBinding.js +++ b/src/TemplateBinding.js @@ -136,12 +136,15 @@ }).join(', '); function isAttributeTemplate(el) { - return semanticTemplateElements[el.tagName] && - el.hasAttribute('template'); + return Boolean(semanticTemplateElements[el.tagName] && + el.hasAttribute('template')); } function isTemplate(el) { - return el.tagName == 'TEMPLATE' || isAttributeTemplate(el); + if (el.isTemplate_ === undefined) + el.isTemplate_ = el.tagName == 'TEMPLATE' || isAttributeTemplate(el); + + return el.isTemplate_; } function isNativeTemplate(el) { @@ -554,10 +557,11 @@ } var stagingDocument = getTemplateStagingDocument(this); - var instance = deepCloneIgnoreTemplateContent(content, stagingDocument); + var instance = createAndBindInstance(content, null, stagingDocument, map, + model, + this.bindingDelegate_, + instanceBindings); - addMapBindings(instance, map, model, this.bindingDelegate_, - instanceBindings); // TODO(rafaelw): We can do this more lazily, but setting a sentinel // in the parent of the template element, and creating it when it's // asked for by walking back to find the iterating template. @@ -746,7 +750,7 @@ return new ObserverTransform(observer, tokens.combinator); } - function processBindings(bindings, node, model, instanceBindings) { + function processBindings(node, bindings, model, instanceBindings) { for (var i = 0; i < bindings.length; i += 2) { var name = bindings[i] var tokens = bindings[i + 1]; @@ -768,8 +772,7 @@ function parseAttributeBindings(element, prepareBindingFn) { assert(element); - var bindings; - var isTemplateNode = isTemplate(element); + var bindings = []; var ifFound = false; var bindFound = false; @@ -787,7 +790,7 @@ name = name.substring(1); } - if (isTemplateNode) { + if (isTemplate(element)) { if (name === IF) { ifFound = true; value = value || '{{}}'; // Accept 'naked' if. @@ -802,13 +805,11 @@ if (!tokens) continue; - bindings = bindings || []; bindings.push(name, tokens); } // Treat