From 2f1bd31d4e75b00407647cc822477d98db6c2d0f Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Tue, 13 Oct 2015 00:13:25 -0700 Subject: [PATCH] Replace _compoundInitializationEffect with statically-initialized literals in the template for attributes & textContent, and by configuring literal values of properties in _configureAnnotationReferences. --- src/lib/annotations/annotations.html | 17 ++++++-- src/lib/bind/effects.html | 4 -- src/standard/annotations.html | 63 ++++++++++++++++------------ src/standard/effectBuilder.html | 8 ---- test/unit/bind-elements.html | 26 +++++++++++- test/unit/bind.html | 35 +++++++++++----- 6 files changed, 98 insertions(+), 55 deletions(-) diff --git a/src/lib/annotations/annotations.html b/src/lib/annotations/annotations.html index 81357e6c35..1128570dc9 100644 --- a/src/lib/annotations/annotations.html +++ b/src/lib/annotations/annotations.html @@ -154,9 +154,12 @@ _parseTextNodeAnnotation: function(node, list) { var parts = this._parseBindings(node.textContent); if (parts) { - // NOTE: use a space here so the textNode remains; some browsers - // (IE) evacipate an empty textNode. - node.textContent = ' '; + // Initialize the textContent with any literal parts + // NOTE: default to a space here so the textNode remains; some browsers + // (IE) evacipate an empty textNode following cloneNode/importNode. + node.textContent = parts.map(function(part) { + return part.literal; + }).join('') || ' '; var annote = { bindings: [{ kind: 'text', @@ -291,6 +294,13 @@ name = name.slice(0, -1); kind = 'attribute'; } + // Initialize attribute bindings with any literal parts + var literal = parts.map(function(part) { + return part.literal; + }).join(''); + if (kind == 'attribute') { + node.setAttribute(name, literal); + } // Clear attribute before removing, since IE won't allow removing // `value` attribute if it previously had a value (can't // unconditionally set '' before removing since attributes with `$` @@ -311,6 +321,7 @@ kind: kind, name: name, parts: parts, + literal: literal, isCompound: parts.length !== 1 }; } diff --git a/src/lib/bind/effects.html b/src/lib/bind/effects.html index af15b803db..2643164e67 100644 --- a/src/lib/bind/effects.html +++ b/src/lib/bind/effects.html @@ -21,10 +21,6 @@ !effect.parts[0].negate; }, - _compoundInitializationEffect: function(source, value, effect) { - this._applyEffectValue(effect); - }, - _annotationEffect: function(source, value, effect) { if (source != effect.value) { value = this._get(effect.value); diff --git a/src/standard/annotations.html b/src/standard/annotations.html index 8e969de4c8..50be217fd3 100644 --- a/src/standard/annotations.html +++ b/src/standard/annotations.html @@ -219,42 +219,51 @@ }, // push configuration references at configure time - _configureAnnotationReferences: function() { - this._configureTemplateContent(); - this._configureCompoundBindings(); - }, - - // nested template contents have been stored prototypically to avoid - // unnecessary duplication, here we put references to the - // indirected contents onto the nested template instances - _configureTemplateContent: function() { - this._notes.forEach(function(note, i) { + _configureAnnotationReferences: function(config) { + var notes = this._notes; + var nodes = this._nodes; + for (var i=0; i Test + {{text}} {{computeFromTrickyLiterals(3, 'tricky\,\'zot\'')}} @@ -364,6 +366,26 @@ }); + +