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

Commit

Permalink
add deserialization support for undefined valued properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jul 24, 2014
1 parent 1a67a4c commit cb37bad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@

(function(scope) {

function noopHandler(value) {
return value;
}

var typeHandlers = {
string: function(value) {
return value;
},
string: noopHandler,
'undefined': noopHandler,
date: function(value) {
return new Date(Date.parse(value) || Date.now());
},
Expand Down
28 changes: 28 additions & 0 deletions test/html/prop-attr-reflection.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@
</head>
<body>

<x-basic></x-basic>
<polymer-element name="x-basic" attributes="nog" noscript>
</polymer-element>

<x-attr-publish></x-attr-publish>
<polymer-element name="x-attr-publish" attributes="nog">
<script>
Polymer('x-attr-publish', {
publish: {
nog: {value: '', reflect: false}
}
});
</script>
</polymer-element>

<x-foo></x-foo>
<polymer-element name="x-foo">
<script>
Expand Down Expand Up @@ -80,8 +95,19 @@
}

document.addEventListener('polymer-ready', function() {
var xbasic = document.querySelector('x-basic');
assert.equal(xbasic.nog, undefined, 'property published with `attributes` has correct initial value');
xbasic.setAttribute('nog', 'hi');
assert.equal(xbasic.nog, 'hi', 'deserialization of property published via `attributes`');

var xattrpublish = document.querySelector('x-attr-publish');
assert.equal(xattrpublish.nog, '', 'property published with `attributes` has correct initial value');
xattrpublish.setAttribute('nog', 'hi');
assert.equal(xattrpublish.nog, 'hi', 'deserialization of property published via `attributes`');

var xcompose = document.querySelector('x-compose');
var xfoo = document.querySelector('x-foo');
assert.equal(xfoo.foo, '', 'property published with info object has correct initial value');
xfoo.foo = 5;
xfoo.setAttribute('def1', '15');
xfoo.def2 = 15;
Expand All @@ -98,6 +124,8 @@
assert.equal(xfoo.baz, xfoo.getAttribute('baz'), 'attribute reflects property');
//
var xbar = document.querySelector('x-bar');
assert.equal(xbar.zim, false, 'property published with info object has correct initial value');
assert.equal(xbar.foo, '', 'property published with info object has correct initial value');
//
xbar.foo = 'foo!';
xbar.zot = 27;
Expand Down

0 comments on commit cb37bad

Please sign in to comment.