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;
case Boolean:
value = (value !== null);
value = (value != null);
break;
case Object:

View File

@ -116,7 +116,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_configureProperties: function(properties, config) {
for (var i in properties) {
var c = properties[i];
// Allow properties set before upgrade on the instance
// Allow properties set before upgrade on the instance
// to override default values. This allows late upgrade + an early set
// to not b0rk accessors on the prototype.
// Perf testing has shown `hasOwnProperty` to be ok here.
@ -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] :
this._get(x.effect.value, config);
if (x.effect.kind == 'attribute') {
value = node.deserialize(value,
value = node.deserialize(node.serialize(value),
node._propertyInfo[name].type);
}
node._configValue(name, value);

View File

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