Serialize before deserialize when configuring attrs. Fixes #3433.

This commit is contained in:
Kevin Schaaf 2016-02-18 18:32:36 -08:00
parent 25d4f224d4
commit ec855827fe
4 changed files with 21 additions and 6 deletions

View File

@ -193,7 +193,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
break; break;
case Boolean: case Boolean:
value = (value !== null); value = (value != null);
break; break;
case Object: case Object:

View File

@ -153,7 +153,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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);
if (x.effect.kind == 'attribute') { if (x.effect.kind == 'attribute') {
value = node.deserialize(value, value = node.deserialize(node.serialize(value),
node._propertyInfo[name].type); node._propertyInfo[name].type);
} }
node._configValue(name, value); node._configValue(name, value);

View File

@ -128,12 +128,18 @@
type: Number, type: Number,
observer: 'attrNumberChanged', observer: 'attrNumberChanged',
value: 0 value: 0
},
attrBoolean: {
type: Boolean,
observer: 'attrBooleanChanged',
// value: true
} }
}, },
created: function() { created: function() {
this.attrDashChanged = sinon.spy(); this.attrDashChanged = sinon.spy();
this.attrNumberChanged = sinon.spy(); this.attrNumberChanged = sinon.spy();
this.attrBooleanChanged = sinon.spy();
} }
}); });
@ -142,7 +148,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}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}"></x-configure-child> <x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}" attr-boolean$="{{attrBoolean}}"></x-configure-child>
</template> </template>
<script> <script>
Polymer({ Polymer({
@ -175,7 +181,10 @@
value: 'attrValue' value: 'attrValue'
}, },
attrNumber: { attrNumber: {
value: '42' value: 42
},
attrBoolean: {
value: false
} }
} }

View File

@ -100,7 +100,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assert.notProperty(e.$.child, 'attr-number'); assert.notProperty(e.$.child, 'attr-number');
assert.strictEqual(e.$.child.attrNumber, 42); assert.strictEqual(e.$.child.attrNumber, 42);
assert.isTrue(e.$.child.attrNumberChanged.calledOnce); assert.isTrue(e.$.child.attrNumberChanged.calledOnce);
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42); assert.strictEqual(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
assert.equal(e.$.child.hasAttribute('attr-boolean'), false);
assert.notProperty(e.$.child, 'attr-boolean');
assert.strictEqual(e.$.child.attrBoolean, false);
assert.isTrue(e.$.child.attrBooleanChanged.calledOnce);
assert.strictEqual(e.$.child.attrBooleanChanged.getCall(0).args[0], false);
}); });
test('pre-register property assignment does not break getters and setters', function() { test('pre-register property assignment does not break getters and setters', function() {