-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- attributes are now reflected to property values at runtime, not only at create time. The rules are the same, the attribute is deserialized to the data type of the property in the element's prototype. - `published` properties are now reflected to attributes at runtime. This is done via observation and all published properties are now observed. Properties are serialized directly to strings and object and undefined valued properties are ignored.
- Loading branch information
Showing
6 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>publish attributes</title> | ||
<script src="../../polymer.js"></script> | ||
<script src="../../tools/test/htmltest.js"></script> | ||
<script src="../../node_modules/chai/chai.js"></script> | ||
</head> | ||
<body> | ||
|
||
<x-foo></x-foo> | ||
<polymer-element name="x-foo" attributes="foo baz" noscript></polymer-element> | ||
|
||
<x-bar></x-bar> | ||
<polymer-element name="x-bar" extends="x-foo"> | ||
<script> | ||
Polymer('x-bar', { | ||
publish: { | ||
zot: 3, | ||
zim: false, | ||
str: 'str', | ||
obj: null | ||
} | ||
}); | ||
</script> | ||
</polymer-element> | ||
|
||
<script> | ||
var assert = chai.assert; | ||
document.addEventListener('WebComponentsReady', function() { | ||
// | ||
var xfoo = document.querySelector('x-foo'); | ||
xfoo.foo = 5; | ||
Platform.flush(); | ||
assert.equal(String(xfoo.foo), xfoo.getAttribute('foo'), 'attribute reflects property as string'); | ||
xfoo.setAttribute('foo', '27'); | ||
assert.equal(xfoo.foo, xfoo.getAttribute('foo'), 'property reflects attribute'); | ||
// | ||
xfoo.baz = 'Hello'; | ||
Platform.flush(); | ||
assert.equal(xfoo.baz, xfoo.getAttribute('baz'), 'attribute reflects property'); | ||
// | ||
var xbar = document.querySelector('x-bar'); | ||
// | ||
xbar.foo = 'foo!'; | ||
xbar.zot = 27; | ||
xbar.zim = true; | ||
xbar.str = 'str!'; | ||
xbar.obj = {hello: 'world'}; | ||
Platform.flush(); | ||
assert.equal(xbar.foo, xbar.getAttribute('foo'), 'inherited published property is reflected'); | ||
assert.equal(String(xbar.zot), xbar.getAttribute('zot'), 'attribute reflects property as number'); | ||
assert.equal(String(xbar.zim), xbar.getAttribute('zim'), 'attribute reflects property as boolean'); | ||
assert.equal(xbar.str, xbar.getAttribute('str'), 'attribute reflects property as published string'); | ||
assert.isFalse(xbar.hasAttribute('obj'), 'attribute does not reflect object property'); | ||
xbar.setAttribute('foo', 'foo!!'); | ||
xbar.setAttribute('zot', 54); | ||
xbar.setAttribute('zim', 'false'); | ||
xbar.setAttribute('str', 'str!!'); | ||
xbar.setAttribute('obj', "{'hello': 'world'}"); | ||
assert.equal(xbar.foo, xbar.getAttribute('foo'), 'property reflects attribute as string'); | ||
assert.equal(xbar.zot, 54, 'property reflects attribute as number'); | ||
assert.equal(xbar.zim, false, 'property reflects attribute as boolean'); | ||
assert.equal(xbar.str, 'str!!', 'property reflects attribute as published string'); | ||
assert.deepEqual(xbar.obj, {hello: 'world'}, 'property reflects attribute as object'); | ||
done(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters