Skip to content

Commit

Permalink
Merge pull request #3444 from Polymer/3443-kschaaf-attr-ser-desr
Browse files Browse the repository at this point in the history
Serialize before deserialize when configuring attrs. Fixes #3443.
  • Loading branch information
Steve Orvell committed Feb 19, 2016
2 parents 25d4f22 + 5ac5ee7 commit 4136a8c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -243,7 +243,7 @@

case 'object':
if (value instanceof Date) {
return value;
return value.toString();
} else if (value) {
try {
return JSON.stringify(value);
Expand Down
7 changes: 5 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,10 @@
var value = (p === x.effect.value) ? config[p] :
this._get(x.effect.value, config);
if (x.effect.kind == 'attribute') {
value = node.deserialize(value,
// For attribute bindings, flow through the same ser/deser
// process to ensure the value is the same as if it were
// bound through the attribute
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 4136a8c

Please sign in to comment.