Skip to content

Commit

Permalink
Serialize before deserialize when configuring attrs. Fixes #3433.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Feb 19, 2016
1 parent 25d4f22 commit ec85582
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/micro/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
break;

case Boolean:
value = (value !== null);
value = (value != null);
break;

case Object:
Expand Down
4 changes: 2 additions & 2 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
_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.
Expand Down Expand Up @@ -153,7 +153,7 @@
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);
Expand Down
13 changes: 11 additions & 2 deletions test/unit/configure-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

});
Expand All @@ -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({
Expand Down Expand Up @@ -175,7 +181,10 @@
value: 'attrValue'
},
attrNumber: {
value: '42'
value: 42
},
attrBoolean: {
value: false
}
}

Expand Down
8 changes: 7 additions & 1 deletion test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@
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() {
Expand Down

0 comments on commit ec85582

Please sign in to comment.