+
Mechanism for the registration of custom, dynamic elements that can be added to a page declaratively.
(basically fully-featured custom html elements)
Because it rocks my face off. Next question.
We want to avoid situations where the following happen:
We finally have the opportunity to reuse front-end code
<video />
<select>
<input />
<button />
<!-- And now there's.. -->
<my-custom-element></my-custom-element>Cornerstone of Web Components.
Registration of element with the document.
<!-- x-fade custom element with the shadow dom exposed -->
<x-fade>
<img src="cool.png">
#shadow-root
<div>
<content select="img">
</div>
<canvas></canvas>
</x-fade>
<!-- What the user/browser sees -->
<x-fade>
<img src="cool.png">
</x-fade>
<!-- Alternative resultant DOM from jQuery -->
<x-fade>
<div>
<img src="cool.png">
</div>
<canvas></canvas>
</x-fade>Does the dirty work of hiding the implementation details.
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../hydrolysis/hydrolysis-analyzer.html">
<link rel="import" href="../iron-doc-viewer/iron-doc-viewer.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="../iron-selector/iron-selector.html">
<link rel="import" href="../paper-header-panel/paper-header-panel.html">
<link rel="import" href="../paper-toolbar/paper-toolbar.html">
<link rel="import" href="../paper-styles/paper-styles.html">
How base components are pulled into your new component for use.
Custom Element Registration
<dom-module id="x-foo">
<template>I am x-foo!</template>
<script>
Polymer({
is: 'x-foo'
});
</script>
</dom-module>Element creation comes with many event tie-ins (created/attached/detached/etc.)
Locally Scoped JS and CSS
CSS styles defined inside Shadow DOM are scoped to the ShadowRoot. This means styles are encapsulated by default.
<dom-module id="seed-element">
<style>
:host {
display: block;
box-sizing: border-box;
}
.author img {
float: left;
margin-right: 5px;
max-height: 100px;
max-width: 100px;
}
</style>
<template>
<h1>seed-element</h1>
<content></content>
<p class="author">
<img src="{{author.image}}">
Cheers,<br/>
<span class="name">{{author.name}}</span>
</p>
</template>
</dom-module>Two-Way Data Binding
<dom-module id="user-view">
<template>
First: <span>{{first}}</span><br>
Last: <span>{{last}}</span>
</template>
<script>
Polymer({
is: 'user-view',
properties: {
first: String,
last: String
}
});
</script>
</dom-module>
<user-view first="Samuel" last="Adams"></user-view>