Skip to content

Commit ec85582

Browse files
committed
Serialize before deserialize when configuring attrs. Fixes #3433.
1 parent 25d4f22 commit ec85582

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/micro/attributes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
break;
194194

195195
case Boolean:
196-
value = (value !== null);
196+
value = (value != null);
197197
break;
198198

199199
case Object:

src/standard/configure.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
_configureProperties: function(properties, config) {
117117
for (var i in properties) {
118118
var c = properties[i];
119-
// Allow properties set before upgrade on the instance
119+
// Allow properties set before upgrade on the instance
120120
// to override default values. This allows late upgrade + an early set
121121
// to not b0rk accessors on the prototype.
122122
// Perf testing has shown `hasOwnProperty` to be ok here.
@@ -153,7 +153,7 @@
153153
var value = (p === x.effect.value) ? config[p] :
154154
this._get(x.effect.value, config);
155155
if (x.effect.kind == 'attribute') {
156-
value = node.deserialize(value,
156+
value = node.deserialize(node.serialize(value),
157157
node._propertyInfo[name].type);
158158
}
159159
node._configValue(name, value);

test/unit/configure-elements.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,18 @@
128128
type: Number,
129129
observer: 'attrNumberChanged',
130130
value: 0
131+
},
132+
attrBoolean: {
133+
type: Boolean,
134+
observer: 'attrBooleanChanged',
135+
// value: true
131136
}
132137
},
133138

134139
created: function() {
135140
this.attrDashChanged = sinon.spy();
136141
this.attrNumberChanged = sinon.spy();
142+
this.attrBooleanChanged = sinon.spy();
137143
}
138144

139145
});
@@ -142,7 +148,7 @@
142148

143149
<dom-module id="x-configure-host">
144150
<template>
145-
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}"></x-configure-child>
151+
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}" attr-boolean$="{{attrBoolean}}"></x-configure-child>
146152
</template>
147153
<script>
148154
Polymer({
@@ -175,7 +181,10 @@
175181
value: 'attrValue'
176182
},
177183
attrNumber: {
178-
value: '42'
184+
value: 42
185+
},
186+
attrBoolean: {
187+
value: false
179188
}
180189
}
181190

test/unit/configure.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@
100100
assert.notProperty(e.$.child, 'attr-number');
101101
assert.strictEqual(e.$.child.attrNumber, 42);
102102
assert.isTrue(e.$.child.attrNumberChanged.calledOnce);
103-
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
103+
assert.strictEqual(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
104+
105+
assert.equal(e.$.child.hasAttribute('attr-boolean'), false);
106+
assert.notProperty(e.$.child, 'attr-boolean');
107+
assert.strictEqual(e.$.child.attrBoolean, false);
108+
assert.isTrue(e.$.child.attrBooleanChanged.calledOnce);
109+
assert.strictEqual(e.$.child.attrBooleanChanged.getCall(0).args[0], false);
104110
});
105111

106112
test('pre-register property assignment does not break getters and setters', function() {

0 commit comments

Comments
 (0)