Polymer
- 11. Markupcanbemeaningfulagain.
<hangout-module>
<hangout-chat from="Paul, Addy" profile="1c18a0e">
<hangout-discussion>
<hangout-message from="Paul" datetime="2013-07-17T12:02">
<p>Feelin' this Web Components thing.</p>
<p>Heard of it?</p>
</hangout-message>
<hangout-message from="Addy" datetime="2013-07-17T12:12">
...
</hangout-message>
<hangout-message>...</hangout-message>
...
</hangout-discussion>
</hangout-chat>
<hangout-chat></hangout-chat>
</hangout-module>
- 17. Exampleofcore-list
<core-list height="800" data="{{collection}} ">
<template>
<div class="todo-item">
<input type="checkbox" checked="{{model.checked}}">
{{model.name}}
</div>
</template>
</core-list>
<script>
Polymer({"collection": [
{"name": "Milk", "checked": false},
{"name": "Bread", "checked": false}
{"name": "Meat", "checked": true}
]})
</script>
- 21. Declarativewebcomponents.
oDeclarative element registration: <polymer-element>
oDeclarative inheritance: <polymer-element extends="...">
oDeclarative two-way data-binding: <input id="input" value="{{foo}}">
oDeclarative event handlers: <button on-click="{{handleClick}}">
oPublished properties: xFoo.bar = 5 <-> <x-foo bar="5">
oProperty change watchers: barChanged: function() {...}
oAutomatic node finding: this.$.input.value = 5
oPointerEvents / PointerGestures by default
Be declarative. Write less code.
- 22. CustomelementswithoutPolymer :(
<template id="template">
<style>input { color: orange; }</style>
<input type="text">
</template>
<script>
var proto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
var t = document.querySelector('#template');
this.createShadowRoot()
.appendChild(document.importNode(t.content, true));
}
}
});
var MyInput = document.register('my-input', {prototype: proto});
</script>
- 23. CustomelementswithPolymer :)
<polymer-element name="my-input" constructor="MyInput" noscript>
<template>
<style>input { color: orange; }</style>
<input type="text">
</template>
</polymer-element>
<my-input></my-input>
// var myInput = document.createElement('my-input');
// var myInput = new MyInput();