Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit cb37bad

Browse files
committed
add deserialization support for undefined valued properties.
1 parent 1a67a4c commit cb37bad

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/lib/deserialize.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
(function(scope) {
1111

12+
function noopHandler(value) {
13+
return value;
14+
}
15+
1216
var typeHandlers = {
13-
string: function(value) {
14-
return value;
15-
},
17+
string: noopHandler,
18+
'undefined': noopHandler,
1619
date: function(value) {
1720
return new Date(Date.parse(value) || Date.now());
1821
},

test/html/prop-attr-reflection.html

+28
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
</head>
1818
<body>
1919

20+
<x-basic></x-basic>
21+
<polymer-element name="x-basic" attributes="nog" noscript>
22+
</polymer-element>
23+
24+
<x-attr-publish></x-attr-publish>
25+
<polymer-element name="x-attr-publish" attributes="nog">
26+
<script>
27+
Polymer('x-attr-publish', {
28+
publish: {
29+
nog: {value: '', reflect: false}
30+
}
31+
});
32+
</script>
33+
</polymer-element>
34+
2035
<x-foo></x-foo>
2136
<polymer-element name="x-foo">
2237
<script>
@@ -80,8 +95,19 @@
8095
}
8196

8297
document.addEventListener('polymer-ready', function() {
98+
var xbasic = document.querySelector('x-basic');
99+
assert.equal(xbasic.nog, undefined, 'property published with `attributes` has correct initial value');
100+
xbasic.setAttribute('nog', 'hi');
101+
assert.equal(xbasic.nog, 'hi', 'deserialization of property published via `attributes`');
102+
103+
var xattrpublish = document.querySelector('x-attr-publish');
104+
assert.equal(xattrpublish.nog, '', 'property published with `attributes` has correct initial value');
105+
xattrpublish.setAttribute('nog', 'hi');
106+
assert.equal(xattrpublish.nog, 'hi', 'deserialization of property published via `attributes`');
107+
83108
var xcompose = document.querySelector('x-compose');
84109
var xfoo = document.querySelector('x-foo');
110+
assert.equal(xfoo.foo, '', 'property published with info object has correct initial value');
85111
xfoo.foo = 5;
86112
xfoo.setAttribute('def1', '15');
87113
xfoo.def2 = 15;
@@ -98,6 +124,8 @@
98124
assert.equal(xfoo.baz, xfoo.getAttribute('baz'), 'attribute reflects property');
99125
//
100126
var xbar = document.querySelector('x-bar');
127+
assert.equal(xbar.zim, false, 'property published with info object has correct initial value');
128+
assert.equal(xbar.foo, '', 'property published with info object has correct initial value');
101129
//
102130
xbar.foo = 'foo!';
103131
xbar.zot = 27;

0 commit comments

Comments
 (0)