mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #3383 from Polymer/3288-kschaaf-attr-config-fix
Configure attr's with property effects. More robust fix for #3288.
This commit is contained in:
commit
5215695e71
@ -351,12 +351,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
// (properties) are case sensitive. Gambit is to map dash-case to
|
// (properties) are case sensitive. Gambit is to map dash-case to
|
||||||
// camel-case: `foo-bar` becomes `fooBar`.
|
// camel-case: `foo-bar` becomes `fooBar`.
|
||||||
// Attribute bindings are excepted.
|
// Attribute bindings are excepted.
|
||||||
|
var propertyName = Polymer.CaseMap.dashToCamelCase(name);
|
||||||
if (kind === 'property') {
|
if (kind === 'property') {
|
||||||
name = Polymer.CaseMap.dashToCamelCase(name);
|
name = propertyName;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
kind: kind,
|
kind: kind,
|
||||||
name: name,
|
name: name,
|
||||||
|
propertyName: propertyName,
|
||||||
parts: parts,
|
parts: parts,
|
||||||
literal: literal,
|
literal: literal,
|
||||||
isCompound: parts.length !== 1
|
isCompound: parts.length !== 1
|
||||||
@ -372,7 +374,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
Polymer.Annotations.findAnnotatedNode(root, annote.parent);
|
Polymer.Annotations.findAnnotatedNode(root, annote.parent);
|
||||||
// unwind the stack, returning the indexed node at each level
|
// unwind the stack, returning the indexed node at each level
|
||||||
if (parent) {
|
if (parent) {
|
||||||
// note: marginally faster than indexing via childNodes
|
// note: marginally faster than indexing via childNodes
|
||||||
// (http://jsperf.com/childnodes-lookup)
|
// (http://jsperf.com/childnodes-lookup)
|
||||||
for (var n=parent.firstChild, i=0; n; n=n.nextSibling) {
|
for (var n=parent.firstChild, i=0; n; n=n.nextSibling) {
|
||||||
if (annote.index === i++) {
|
if (annote.index === i++) {
|
||||||
|
@ -136,15 +136,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
for (var i=0, l=fx.length, x; (i<l) && (x=fx[i]); i++) {
|
for (var i=0, l=fx.length, x; (i<l) && (x=fx[i]); i++) {
|
||||||
// TODO(kschaaf): compound bindings (as well as computed effects)
|
// TODO(kschaaf): compound bindings (as well as computed effects)
|
||||||
// are excluded from top-down configure for now; to be revisited
|
// are excluded from top-down configure for now; to be revisited
|
||||||
if (x.kind === 'annotation' &&
|
if (x.kind === 'annotation' && !x.isCompound) {
|
||||||
x.effect.kind !== 'attribute' &&
|
|
||||||
!x.isCompound) {
|
|
||||||
var node = this._nodes[x.effect.index];
|
var node = this._nodes[x.effect.index];
|
||||||
|
var name = x.effect.propertyName;
|
||||||
// seeding configuration only
|
// seeding configuration only
|
||||||
if (node._configValue) {
|
if (node._propertyEffects && node._propertyEffects[name]) {
|
||||||
var value = (p === x.effect.value) ? config[p] :
|
var value = (p === x.effect.value) ? config[p] :
|
||||||
this._get(x.effect.value, config);
|
this._get(x.effect.value, config);
|
||||||
node._configValue(x.effect.name, value);
|
if (x.effect.kind == 'attribute') {
|
||||||
|
value = node.deserialize(value,
|
||||||
|
node._propertyInfo[name].type);
|
||||||
|
}
|
||||||
|
node._configValue(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
kind: note.kind,
|
kind: note.kind,
|
||||||
index: index,
|
index: index,
|
||||||
name: note.name,
|
name: note.name,
|
||||||
|
propertyName: note.propertyName,
|
||||||
value: part.value,
|
value: part.value,
|
||||||
isCompound: note.isCompound,
|
isCompound: note.isCompound,
|
||||||
compoundIndex: part.compoundIndex,
|
compoundIndex: part.compoundIndex,
|
||||||
|
@ -283,11 +283,7 @@ suite('hostAttributes', function() {
|
|||||||
// applied to property with effect
|
// applied to property with effect
|
||||||
assert.strictEqual(compose.$.basic.prop, 'compose');
|
assert.strictEqual(compose.$.basic.prop, 'compose');
|
||||||
assert.equal(compose.$.basic.propChangedCount, 1);
|
assert.equal(compose.$.basic.propChangedCount, 1);
|
||||||
// Note: Attribute binding does not participate in efficient configuration
|
assert.equal(compose.$.basic.attr1ChangedCount, 1);
|
||||||
// per #3288. As such, a property bound with an attribute binding will
|
|
||||||
// see its default value first, then be overwritten when the attribute
|
|
||||||
// binding runs and re-deserializes to the property, hence 2 observer calls
|
|
||||||
assert.equal(compose.$.basic.attr1ChangedCount, 2);
|
|
||||||
assert.equal(compose.prop2, 'hi');
|
assert.equal(compose.prop2, 'hi');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,7 +119,21 @@
|
|||||||
},
|
},
|
||||||
stomp: {
|
stomp: {
|
||||||
value: 5
|
value: 5
|
||||||
|
},
|
||||||
|
attrDash: {
|
||||||
|
observer: 'attrDashChanged',
|
||||||
|
value: 'default'
|
||||||
|
},
|
||||||
|
attrNumber: {
|
||||||
|
type: Number,
|
||||||
|
observer: 'attrNumberChanged',
|
||||||
|
value: 0
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created: function() {
|
||||||
|
this.attrDashChanged = sinon.spy();
|
||||||
|
this.attrNumberChanged = sinon.spy();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -128,7 +142,7 @@
|
|||||||
|
|
||||||
<dom-module id="x-configure-host">
|
<dom-module id="x-configure-host">
|
||||||
<template>
|
<template>
|
||||||
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}"></x-configure-child>
|
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}"></x-configure-child>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
Polymer({
|
Polymer({
|
||||||
@ -158,7 +172,10 @@
|
|||||||
value: 5
|
value: 5
|
||||||
},
|
},
|
||||||
attrValue: {
|
attrValue: {
|
||||||
value: 'attrValue'
|
value: 'attrValue',
|
||||||
|
},
|
||||||
|
attrNumber: {
|
||||||
|
value: '42'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,12 +81,28 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
assert.equal(e.readOnly, 'default');
|
assert.equal(e.readOnly, 'default');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('properties for attribute bindings not configured', function() {
|
test('attribute bindings to properties without effects not configured', function() {
|
||||||
var e = document.querySelector('x-configure-host');
|
var e = document.querySelector('x-configure-host');
|
||||||
assert.equal(e.$.child.getAttribute('attr'), 'attrValue');
|
assert.equal(e.$.child.getAttribute('attr'), 'attrValue');
|
||||||
assert.equal(e.$.child.attr, undefined);
|
assert.equal(e.$.child.attr, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('attribute bindings to properties with effects configured', function() {
|
||||||
|
var e = document.createElement('x-configure-host');
|
||||||
|
|
||||||
|
assert.equal(e.$.child.getAttribute('attr-dash'), 'attrValue');
|
||||||
|
assert.notProperty(e.$.child, 'attr-dash');
|
||||||
|
assert.equal(e.$.child.attrDash, 'attrValue');
|
||||||
|
assert.isTrue(e.$.child.attrDashChanged.calledOnce);
|
||||||
|
assert.equal(e.$.child.attrDashChanged.getCall(0).args[0], 'attrValue');
|
||||||
|
|
||||||
|
assert.equal(e.$.child.getAttribute('attr-number'), '42');
|
||||||
|
assert.notProperty(e.$.child, 'attr-number');
|
||||||
|
assert.strictEqual(e.$.child.attrNumber, 42);
|
||||||
|
assert.isTrue(e.$.child.attrNumberChanged.calledOnce);
|
||||||
|
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user