Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
don't serialize default values.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 8, 2014
1 parent dd35960 commit 8b2aeda
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions elements/x-dom-serializer/x-dom-serializer.html
Expand Up @@ -53,19 +53,18 @@
if (n == 'textContent') {
return;
}
if (node.publish && node.publish[n] === undefined) {
/*if (node.publish && node.publish[n] === undefined) {
return;
}
}*/
if (binding) {
v = '{{ ' + binding + ' }}';
} else if (!((v || v === 0) && (typeof v === 'string' || typeof v === 'number' ||
typeof v === 'boolean'))) {
v = null;
}
if (v != null) {
attributes[n.toLowerCase()] = v;
// TODO(sorvell): should have a better way to get defaultValue.
if (!this.shouldSerializeProperty(v, node.__proto__[n])) {
return;
}
});
attributes[n.toLowerCase()] = v;
}, this);
for (var i=0, a, n; (a = node.attributes[i]); i++) {
n = a.name.toLowerCase();
if (attributes[n] === undefined) {
Expand All @@ -75,6 +74,12 @@
this.filterAttributes(attributes);
return attributes;
},
shouldSerializeProperty: function(value, defaultValue) {
return (value !== defaultValue)
&& (value || value === 0)
&& (typeof value === 'string' || typeof value === 'number' ||
typeof value === 'boolean');
},
// special handling for certain attributes: style, class
filterAttributes: function(attributes) {
for (var i in attributes) {
Expand Down

0 comments on commit 8b2aeda

Please sign in to comment.