Merge pull request #3161 from Polymer/3157-kschaaf-domif-textnode

Custom setProperty for bindings to hidden textNodes. Fixes #3157.
This commit is contained in:
Steve Orvell 2015-12-07 13:50:11 -08:00
commit 2c6161c253
3 changed files with 39 additions and 4 deletions

View File

@ -124,6 +124,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
archetype._scopeElementClass = this._scopeElementClassImpl;
archetype.listen = this._listenImpl;
archetype._showHideChildren = this._showHideChildrenImpl;
archetype.__setPropertyOrig = this.__setProperty;
archetype.__setProperty = this.__setPropertyImpl;
// boilerplate code
var _constructor = this._constructorImpl;
var ctor = function TemplateInstance(model, host) {
@ -168,6 +170,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
},
__setPropertyImpl: function(property, value, fromAbove, node) {
if (node && node.__hideTemplateChildren__ && property == 'textContent') {
property = '__polymerTextContent__';
}
this.__setPropertyOrig(property, value, fromAbove, node);
},
_debounceTemplate: function(fn) {
Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', fn));
},
@ -242,7 +251,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}, {
kind: 'notify',
fn: Polymer.Bind._notifyEffect,
effect: {event:
effect: {event:
Polymer.CaseMap.camelToDashCase(parentProp) + '-changed'}
}];
Polymer.Bind._createAccessors(proto, parentProp, effects);
@ -259,7 +268,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
this._extendTemplate(template, proto);
template._pathEffector = function(path, value, fromAbove) {
return self._pathEffectorImpl(path, value, fromAbove);
return self._pathEffectorImpl(path, value, fromAbove);
}
}
},

View File

@ -165,13 +165,18 @@
<div>1</div>
<div>2</div>
<div>3</div>
Stuff
{{text}}
<div>4</div>
</template>
</template>
<script>
Polymer({
is: 'x-textcontent'
is: 'x-textcontent',
properties: {
text: {
value: 'Stuff'
}
}
});
</script>
</dom-module>

View File

@ -495,6 +495,27 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
document.body.removeChild(x);
});
test('binding to text nodes changed while if=false', function() {
var x = document.createElement('x-textcontent');
document.body.appendChild(x);
x.$.domIf.render();
var stamped = Polymer.dom(x.root).childNodes;
assert.equal(stamped.length, 12);
assert.equal(stamped[7].textContent.trim(), 'Stuff');
x.$.domIf.if = false;
x.$.domIf.render();
x.text = 'Hollaaaaa!';
stamped = Polymer.dom(x.root).childNodes;
assert.equal(stamped.length, 12);
assert.equal(stamped[7].textContent.trim(), '');
x.$.domIf.if = true;
x.$.domIf.render();
stamped = Polymer.dom(x.root).childNodes;
assert.equal(stamped.length, 12);
assert.equal(stamped[7].textContent.trim(), 'Hollaaaaa!');
document.body.removeChild(x);
});
});
suite('queueing race conditions', function() {