SlideShare a Scribd company logo
1 of 87
Download to read offline
Conception d'Applications
Interactives :
Applications Web et JEE
Séance #1
Côté navigateur
HTML5 / CSS / JS / Polymer
3/3 - Web Components & Polymer
Description du module
● Côté navigateur
○ HTML5 / CSS / JS - Polymer
● Côté serveur - Concepts
○ Introduction à JEE : servlets, JSP, frameworks… - SparkJava
● Forge JavaScript
○ Une forge logicielle pour JavaScript : Grunt/Gulp, Bower, Yeoman
● Côté serveur - NodeJS
○ NodeJS, ExpressJS, APIs
● Écosystème de la webapp
○ Introduction à NoSQL : MongoDB, Redis, Cassandra…
● Autour de la webapp
○ Forge logicielle en Java - Test-driven development
● Examen et exposées des projets
Introduction
Because I love to tell old stories
Warning : I’m a web developer
And when I tell stories, I do it from the webdev POV
So please, thick-client devs, allow me some oversimplifications
Image : TylkoMrok.pl
At the beginning we had the thick
client
● Widget : basic building blocks of your UI
○ Encapsulation
○ Reutilisation
In thick client you create your UI by
assembling widgets
Image : Wikipedia
Web development was unlike thick-
client
● HTML/CSS/JS didn't support widgets
○ Pages were the building blocks
Web apps were page oriented
Image : IBM
GWT gave back widgets to web devs
● GWT used a thick-client-like development paradigm
○ Widgets, properties, events
GWT web apps were widget oriented :
Single-page apps
Image : GWT Mail sample app
Single-page apps are a current trend
● From UX POV single-page apps are richer
○ But making them without widgets is risky and difficult
HTML/CSS/JS needed a widget standard
Image : Ken Schultz comedy juggler
Web Components
Reinventing the wheel...
and this time making it round
Example : the Google+ button
● If you want to place a Google+ button in your page
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-annotation="inline" data-width="300"
></div>
<!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
Example : the Google+ button
● And what I would like is simple
<g:plusone></g:plusone>
Example : the Google+ button
● To be fair, Google already makes it simpler
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
</script>...
<g:plusone></g:plusone>
● They create directives with JS to emulate components
○ AngularJS approach
○ Respecting the spirit of the future standard
○ Working in current browsers
Totally non standard...
Another example : the RIB
● If you're French, you know what a RIB is
○ A banking account identification number
● To show a RIB in HTML:
○ All styling & surface control must be done elsewhere by CSS and JS
● What I would like
○ A semantic tag
○ With encapsulated styling and surface controlling
<div class="rib">58496 87451 00014500269 74</div>
<x-rib banque="58496" guichet="87451" compte="00014500269" cle="74" />
But we already can do that!
● In most modern frameworks we can already do
components, in a way or another
○ And all those ways are different!
○ Using different JavaScript libraries
○ Almost no component sharing between frameworks
● W3C's works aim to make a standard way
○ Supported natively by all browsers
○ Allowing for component reuse
Web Components : a W3C standard
● Web Components standard is being worked at W3C
○ We all know what this means
■ Clue : HTML5
They will work for years, bickering and fighting
Browsers and devs will use the WiP document
The 4 pillars of the Web Components
● Templates
● Shadow DOM
● Custom Elements
● Imports
Templates
Image: Instructables
The clone wars
Templates before <template>
● How did we do templating before
○ Using display:none or hidden
○ Putting it inside a script
■ Type unknown to browser, it isn't interpreted
■ Markup easily recovered via .innerHTML and reused
■ Approach used by many template engines
<div id="commentTemplate" class="comment" hidden>
<img src=""> <div class="comment-text"></div>
</div>
<script id="commentTemplate" type="text/template">
<div class="comment">
<img src=""> <div class="comment-text"></div>
</div>
</script>
● Uniformising those approach with a new tag
● Content inside the tag is parsed but not interpreted
○ HTML not shown
○ Resources are not loaded
○ Scripts not executed
The <template> tag
<template id="commentTemplate">
<div>
<img src="">
<div class="comment-text"></div>
</div>
</template>
Template instantiation
● Create the elements in page by cloning the template
<template id="commentTemplate">
<div class="comment">
<img src=""> <div class="comment-text"></div>
</div>
</template>
<script>
function addComment(imageUrl, text) {
var t = document.querySelector("#commentTemplate");
var comment = t.content.cloneNode(true);
// Populate content.
comment.querySelector('img').src = imageUrl;
comment.querySelector('.comment-text').textContent = text;
document.body.appendChild(comment);
}
</script>
Shadow DOM
Image: Springfield Punx
Join the shadowy side,
young padawan
Encapsulation
● Each component should have
○ Public interface
○ Private inner code
● When using a component
○ You manipulate the interface only
○ You don't need to know anything about inner code
○ No conflict between inner code and outside code
Encapsulation before Shadow DOM
● Only a way :
<innerFrame>
Image : Star Trek the Next Generation
Your browser cheats on you
● Considerer this simple slider
○ How does the browser deal with it?
■ With HTML, CSS and JS!
○ It has a movable element, I can recover it's position
■ Why cannot see it in DOM tree?
Browsers hide DOM sub-trees for standard components
They have a public interface and hidden inner code
That's Shadow DOM!
<input id="foo" type="range">
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
</video>
My name is DOM, Shadow DOM
● Shadow DOM: ability of the browser to
○ Include a DOM subtree into the rendering
○ But not into the main document DOM tree
● In Chome you can see the Shadow DOM
○ By activating the option in Inspector
Looking into the Shadow
● For the slider :
Shadow DOM is already here
● Browser use it everyday...
○ For their inner needs
○ Not exposed to developers
● Web Components makes Shadow DOM available
○ You can use it for your own components
Image: Springfield Punx
Using Shadow DOM
● There is a host element
○ A normal element in DOM tree
● A shadow root is associated
to the host
○ Using the createShadowRoot method
○ The shadow root is the root of the hidden
DOM tree
Image: W3C
Using Shadow DOM
● Quick and dirty Shadow DOM
○ DOM tree only shows
<div id="emptyHost"></div>
○ Rendered HTML shows
Not empty anymore!
○ Markup in innerHTML is ugly
<div id="emptyHost"></div>
<script>
var host = document.querySelector('#emptyHost');
var root = host.createShadowRoot();
root.innerHTML = "<h1>Not empty anymore!</h4>";
</script>
Using Shadow DOM
● Shadow DOM with templates
<div id="emptyHost"></div>
<template id="commentTemplate"> [...] </template>
<script>
var host = document.querySelector('#emptyHost');
var shadowRoot = host.webkitCreateShadowRoot();
function addComment(imageUrl, text) { [...] }
function addShadowedElement() {
var instanceTemplate =
addComment("http://lostinbrittany.org/avatar.png",
"This is a nice comment made by a nice guy");
shadowRoot.appendChild(instanceTemplate);
}
</script>
● CSS defined in the Shadow DOM remains there
● Outside styles don't affect Shadowed content
This is a title
And this is widget title
Widget content here
Shadow DOM et CSS
<h1>This is a title</h1>
<div id="widget">
#document-fragment
<style>
div {border: solid 1px red;}
h1 {color: blue;}
</style>
<h1>And this is widget title</h1>
<div>Widget content here</div>
</div>
Shadow DOM et CSS
● Styling the host element : @host
<template id="template">
<style>
@host {
button { border-radius: 5px; }
}
</style>
<content></content>
</template>
<button id="host">My Button</button>
<script>
var host = document.querySelector('#host');
var root = host.createShadowRoot();
var shadowContent =
document.querySelector("#template").content.cloneNode(true);
root.appendChild(shadowContent);
</script>
My Button
Example
Image: The Brick Blogger
Elemental mayhem !
Elemental mayhem !
Custom elements : the HTML side
● An element encloses template, lifecycle and behaviour
○ Templates done with <template> tag
<!-- Template Definition -->
<template id="template">
<style>
...
</style>
<div id="container">
<img src="http://webcomponents.org/img/logo.svg">
<content select="h1"></content>
</div>
</template>
<!-- Custom Element usage -->
<x-component>
<h1>This is Custom Element</h1>
</x-component>
Custom elements: the JavaScript side
● An element encloses template, lifecycle and behaviour
○ JavaScript to define behaviour and register the element
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() {
// Adding a Shadow DOM
var root = this.createShadowRoot();
// Adding a template
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
root.appendChild(clone);
}
var XComponent = document.registerElement('x-component', {
prototype: proto
});
Extending other elements
● To create element A that extends element B,
element A must inherit the prototype of element B
var MegaButton = document.registerElement('mega-button', {
prototype: Object.create(HTMLButtonElement.prototype),
extends: 'button'
});
Imports
Image: Brikipedia
Because you hate long files
● Custom elements can be loaded from external files
○ Using the link tag:
○ Only <decorator> and <element> are interpreted
○ The DOM of this document is available to script
○ Documents are retrieved according to cross-origin policies
Imports
<link rel="import" href="goodies.html">
Can I use?
Image: Christoph Hauf
If not, why are you telling us all this sh*t?
Are we componentized yet?
WebComponents.org
Polymer
Webcomponents for today's web
● A Google project
○ Introduced in Google I/O 2013
○ New type of library for the web
○ Built on top of Web Components
○ Designed to leverage the evolving web platform
Version 1.0 released at Google IO 2015
Oh yeah!
Polymer
● What does it means ?
○ Polymer is comprised of two efforts :
■ A paper platform to give Web Component
capabilities to modern browsers
● Shims for all modern browsers
● Shared with Mozilla x-tag project
■ A next-generation web framework built upon
this core platform
● Called Polymer Elements
Polymer
Polymer
Polymer elements
● Principes:
○ Everything is a component
■ Encapsulation is needed for a component oriented application
○ Extreme pragmatism
■ Boilerplate is bad
■ Anything repetitive should be re-factored into a component
● Handled by Polymer itself or
● Added into the browser platform itself
Polymer
● Principes:
○ Salt to taste
■ Use as much or as little of the framework as you wish.
● You want polyfills only :
load polymer-all/platform/platform.js
● You want extra bits :
load polymer-all/polymer/polymer.js
○ Polymer elements
Polymer
● Platform technologies are already functional
○ You can use it to add templates, shadow DOM, custom elements and
imports to your app
● Lots of examples in the site
Polymer
● X-Tag is a small JavaScript library
○ created and supported by Mozilla
○ that brings Web Components capabilities
○ to all modern browsers
● Polymer vs X-Tag?
○ Different features and approaches
○ Mozilla and Google are collaborating
■ building the shared polyfills platform
What about X-Tag?
● AngularJS directives allow to create custom elements
○ Same spirit, different implementation
And AngularJS?
<!doctype html>
<html>
<head>
<title>Directive Test</title>
<script type="text/javascript" src="jquery.min.js" ></script>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="mydirectives.js"></script>
</head>
<body ng-app>
<div test-elem></div>
</body>
</html>
Polymer today
Because you can already play!
Step-1 : get Polymer
Step 2 - Use an element
<!-- 1. Polyfill Web Components support for older browsers -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"
></script>
<!-- 2. Import element -->
<link rel="import" href="bower_components/google-map/google-map.html">
<!-- 3. Use element -->
<google-map latitude="47.205403" longitude="-1.5631069" zoom="17"></google-map>
Step-3.1 : define an element
<dom-module name="x-web2day">
<template>
<style>
@host { /*...*/ }
</style>
<div id="box">
<h1>Bonsoir web2day !</h1>
<p><content></content></p>
</div>
</template>
</dom-module>
<script>
Polymer({ is: 'x-web2day'});
</script>
Step-3.2 : load Polymer, import your
element
<!DOCTYPE html>
<html>
<head>
<!-- 1. Load Polymer -->
<script src="bower_components/webcomponentsjs/webcomponents.js">
</script>
<!-- 2. Load a component -->
<link rel="import" href="x-web2day.html">
</head>
<body>
<!-- 3. Declare the component by its tag. -->
<x-web2day>Et je peux mettre mon texte ici
</x-web2day>
</body>
</html>
Step-3.3 : enjoy
Step-4.1 : Add properties/methods
<dom-module id="x-web2day">
<template>
<style> /.../ </style>
<div id="box">
<h1>{{greet}}</h1>
<p><content></content></p>
<div><button on-click="alertHello">Click me!</button></div>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'x-web2day',
properties: {
whoami: { type: String, value: "web2day" },
greet: { type: String, computed: 'doGreet(whoami)' }
},
alertHello: function() { alert("Hello "+this.whoami);},
doGreet: function(who) { return "Hello "+who}
});
</script>
Step-4.2 : enjoy
Step-4.1 : Two-ways databinding
<dom-module id="x-web2day">
<template>
<style>/*...*/</style>
<div id="box">
<h1>Bonjour <span>{{whoami}}</span></h1>
<p><content></content></p>
<!-- iron-input exposes a two-way bindable input value -->
<input is="iron-input"
bind-value="{{whoami}}"
placeholder="Your name here..." />
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'x-web2day',
properties: {
whoami: { type: String, value: "web2day", notify: true
}
}
});
</script>
Step-5.2 : enjoy
Catalog of elements
Polymer iron elements
Set of visual and non-visual utility elements
Example: iron-ajax
Paper Elements
Image: ToyPro
Material Design on Polymer, oh yeah!
Android Lollipop's look & feel
Material Design is a visual language that synthesizes the classic principles of good
design with the innovation and possibility of technology and science
It'slike
a
flat
design,butin
3D!
Nicevisualeffects!
Material Design
Visual language joining good design with technical innovation to
create an unified experience across platforms and device sizes
Responsive!
Responsive!
What's material design?
http://www.google.com/design/spec/material-design/
UIs implementing a 3D metaphor : lights & shadows, stacking
Polymer paper elements
Set of visual elements that implement Material Design
<paper-toolbar>
<link rel=“import”
href=“paper-toolbar.html”>
<paper-toolbar>
<div>Title</div>
<paper-icon-button icon=“menu”>
</paper-icon-button>
</paper-toolbar>
<paper-header-panel>
<link rel=“import”
href=“paper-toolbar.html”>
<link rel=“import”
href=“paper-header-panel.html”>
<paper-header-panel flex>
<paper-toolbar>
<paper-icon-button icon=“menu">
</paper-icon-button>
<div>I/O 2014</div>
</paper-toolbar>
<div class=“content”>…</div>
</paper-header-panel>
Elements are configurable
<paper-header-panel mode=“scroll” flex>
<paper-toolbar>
<paper-icon-button icon=“menu">
</paper-icon-button>
<div>I/O 2014</div>
</paper-toolbar>
<div class=“content”>…</div>
</paper-header-panel>
Toolbar will scroll with the page
Responsivity from the beginning
<paper-drawer-panel>
<div drawer>
Drawer panel…
</div>
<div main>
Main panel...
</div>
</paper-drawer-panel>
<paper-ripple>
<div class=“card”>
<img src=“learning.svg”>
<paper-ripple fit></paper-ripple>
</div>
<div class=“card”>
<img src=“science.svg”>
<paper-ripple fit></paper-ripple>
</div>
<div class=“card”>
<img src=“food.svg”>
<paper-ripple fit></paper-ripple>
</div>
<div class=“card”>
<img src=“earth.svg”>
<paper-ripple fit></paper-ripple>
</div>
A reactive ink effect for indicating
touch and mouse actions
A full demo of Polymer Paper
https://www.polymer-project.org/apps/topeka/
Fully responsive
Gold Elements
Image: Pinterest
For e-commerce use-cases
Polymer gold elements
Set of elements for e-commerce use-cases, like checkout flows
Google Web Components
Image: LikeCool
From widgets to full apps
Google Web Components
From small widgets to full-scoped apps
Other available
web components
Image: KNP Labs
The more, the merrier!
Mozilla Brick
Bosonic
Conclusion
Image: dcplanet.fr
That's all folks!
You want to know more?
● W3C's Introduction to Web Components
● HTML5 Rocks' Shadow DOM 101 & HTML5 Rocks' Shadow DOM 201: CSS
● WebComponents.org's Introduction to Shadow DOM
● Polymer, X-Tags, Mozilla Brick
● MutationObserver & Object.observe
Thank you !

More Related Content

What's hot

Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3
Karambir Singh Nain
 
Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022
NAVER D2
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
Laurence Svekis ✔
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Patrick Lauke
 

What's hot (20)

JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web framework
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
Introduction to web components
Introduction to web componentsIntroduction to web components
Introduction to web components
 
High-Quality JavaScript
High-Quality JavaScriptHigh-Quality JavaScript
High-Quality JavaScript
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
 
Web Components
Web ComponentsWeb Components
Web Components
 
Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3Building a Better Web with HTML5 and CSS3
Building a Better Web with HTML5 and CSS3
 
Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 
Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022Deview 2013 mobile browser internals and trends_20131022
Deview 2013 mobile browser internals and trends_20131022
 
lect9
lect9lect9
lect9
 
JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
Angularjs vs Dojo toolkit | SuperSpeaker@CodeCamp Iasi 2014
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
How Browser Works?
How Browser Works?How Browser Works?
How Browser Works?
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web Frameworks
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
 
10 java script projects full source code
10 java script projects full source code10 java script projects full source code
10 java script projects full source code
 
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
 

Similar to ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Polymer

2014 03-25 - GDG Nantes - Web Components avec Polymer
2014 03-25 - GDG Nantes - Web Components avec Polymer2014 03-25 - GDG Nantes - Web Components avec Polymer
2014 03-25 - GDG Nantes - Web Components avec Polymer
Horacio Gonzalez
 
Extending WordPress' TinyMCE
Extending WordPress' TinyMCEExtending WordPress' TinyMCE
Extending WordPress' TinyMCE
Hristo Chakarov
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon London
Emma Jane Hogbin Westby
 

Similar to ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Polymer (20)

Web components
Web componentsWeb components
Web components
 
2014 03-25 - GDG Nantes - Web Components avec Polymer
2014 03-25 - GDG Nantes - Web Components avec Polymer2014 03-25 - GDG Nantes - Web Components avec Polymer
2014 03-25 - GDG Nantes - Web Components avec Polymer
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
Extending WordPress' TinyMCE
Extending WordPress' TinyMCEExtending WordPress' TinyMCE
Extending WordPress' TinyMCE
 
2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptx
 
GDayX - Advanced Angular.JS
GDayX - Advanced Angular.JSGDayX - Advanced Angular.JS
GDayX - Advanced Angular.JS
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Reaching for the Future with Web Components and Polymer
Reaching for the Future with Web Components and PolymerReaching for the Future with Web Components and Polymer
Reaching for the Future with Web Components and Polymer
 
Neoito — How modern browsers work
Neoito — How modern browsers workNeoito — How modern browsers work
Neoito — How modern browsers work
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
 
Developing Custom WordPress Themes for Clients
Developing Custom WordPress Themes for ClientsDeveloping Custom WordPress Themes for Clients
Developing Custom WordPress Themes for Clients
 
Html5
Html5Html5
Html5
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon London
 

More from Horacio Gonzalez

Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
Horacio Gonzalez
 
Bootcamp d'Initiation à Android - 2013/11/30 - Live coding : Hello world!
Bootcamp d'Initiation à Android  - 2013/11/30 - Live coding :   Hello world!Bootcamp d'Initiation à Android  - 2013/11/30 - Live coding :   Hello world!
Bootcamp d'Initiation à Android - 2013/11/30 - Live coding : Hello world!
Horacio Gonzalez
 
Bootcamp d'Initiation à Android - 2013/11/30
Bootcamp d'Initiation à Android  - 2013/11/30Bootcamp d'Initiation à Android  - 2013/11/30
Bootcamp d'Initiation à Android - 2013/11/30
Horacio Gonzalez
 

More from Horacio Gonzalez (20)

Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
Il n'y a pas que Polymer dans la vie… - RennesJS - 2017-06-27
 
But there is no web component for that - Web Components Remote Conference - 2...
But there is no web component for that - Web Components Remote Conference - 2...But there is no web component for that - Web Components Remote Conference - 2...
But there is no web component for that - Web Components Remote Conference - 2...
 
Mixité dans le monde des WebComponents - DevFest Toulouse - 2017-09-27
 Mixité dans le monde des WebComponents - DevFest Toulouse - 2017-09-27 Mixité dans le monde des WebComponents - DevFest Toulouse - 2017-09-27
Mixité dans le monde des WebComponents - DevFest Toulouse - 2017-09-27
 
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 2/3 - HTML5, CSS3, Twitter B...
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 2/3 - HTML5, CSS3, Twitter B...ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 2/3 - HTML5, CSS3, Twitter B...
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 2/3 - HTML5, CSS3, Twitter B...
 
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JSENIB 2016 2017 - CAI Web S02E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
ENIB 2016 2017 - CAI Web S02E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
 
Battle of Frameworks: Polymer - Meetup Paris Web Components - 2016-09
Battle of Frameworks: Polymer - Meetup Paris Web Components - 2016-09Battle of Frameworks: Polymer - Meetup Paris Web Components - 2016-09
Battle of Frameworks: Polymer - Meetup Paris Web Components - 2016-09
 
Mixing Web Components - Best of Web Paris - 2016 06-09
Mixing Web Components - Best of Web Paris - 2016 06-09Mixing Web Components - Best of Web Paris - 2016 06-09
Mixing Web Components - Best of Web Paris - 2016 06-09
 
Polymer in the real life - Devoxx France - 2016 04-20
Polymer in the real life - Devoxx France - 2016 04-20Polymer in the real life - Devoxx France - 2016 04-20
Polymer in the real life - Devoxx France - 2016 04-20
 
Warp10: collect, store and manipulate sensor data - BreizhCamp - 2016 03-24
Warp10: collect, store and manipulate sensor data - BreizhCamp - 2016 03-24 Warp10: collect, store and manipulate sensor data - BreizhCamp - 2016 03-24
Warp10: collect, store and manipulate sensor data - BreizhCamp - 2016 03-24
 
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 2/3 - HTML5 / CSS3 / Twitter...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 2/3 - HTML5 / CSS3 / Twitter...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 2/3 - HTML5 / CSS3 / Twitter...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 2/3 - HTML5 / CSS3 / Twitter...
 
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQLENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
ENIB 2015 2016 - CAI Web S02E03 - Forge JS 2/4 - MongoDB and NoSQL
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 1/3 - HTTP, HTML, CSS JS
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 1/3 - HTTP, HTML, CSS JSENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 1/3 - HTTP, HTML, CSS JS
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 1/3 - HTTP, HTML, CSS JS
 
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQLENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
ENIB 2015-2016 - CAI Web - S01E01- MongoDB and NoSQL
 
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 2/3 - HTML5, CSS3, Twitte...
ENIB 2015-2016 - CAI Web -  S01E01- Côté navigateur 2/3 - HTML5, CSS3, Twitte...ENIB 2015-2016 - CAI Web -  S01E01- Côté navigateur 2/3 - HTML5, CSS3, Twitte...
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 2/3 - HTML5, CSS3, Twitte...
 
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
ENIB 2015-2016 - CAI Web -  S01E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JSENIB 2015-2016 - CAI Web -  S01E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 1/3 - HTTP, HTML, CSS, JS
 
Mixing Web Components - Paris Web Components - 2015 09-16
Mixing Web Components - Paris Web Components - 2015 09-16 Mixing Web Components - Paris Web Components - 2015 09-16
Mixing Web Components - Paris Web Components - 2015 09-16
 
Steven Le Roux - Kafka et Storm au service de la lutte antiDDoS à OVH - Soiré...
Steven Le Roux - Kafka et Storm au service de la lutte antiDDoS à OVH - Soiré...Steven Le Roux - Kafka et Storm au service de la lutte antiDDoS à OVH - Soiré...
Steven Le Roux - Kafka et Storm au service de la lutte antiDDoS à OVH - Soiré...
 
Bootcamp d'Initiation à Android - 2013/11/30 - Live coding : Hello world!
Bootcamp d'Initiation à Android  - 2013/11/30 - Live coding :   Hello world!Bootcamp d'Initiation à Android  - 2013/11/30 - Live coding :   Hello world!
Bootcamp d'Initiation à Android - 2013/11/30 - Live coding : Hello world!
 
Bootcamp d'Initiation à Android - 2013/11/30
Bootcamp d'Initiation à Android  - 2013/11/30Bootcamp d'Initiation à Android  - 2013/11/30
Bootcamp d'Initiation à Android - 2013/11/30
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Polymer

  • 1. Conception d'Applications Interactives : Applications Web et JEE Séance #1 Côté navigateur HTML5 / CSS / JS / Polymer 3/3 - Web Components & Polymer
  • 2. Description du module ● Côté navigateur ○ HTML5 / CSS / JS - Polymer ● Côté serveur - Concepts ○ Introduction à JEE : servlets, JSP, frameworks… - SparkJava ● Forge JavaScript ○ Une forge logicielle pour JavaScript : Grunt/Gulp, Bower, Yeoman ● Côté serveur - NodeJS ○ NodeJS, ExpressJS, APIs ● Écosystème de la webapp ○ Introduction à NoSQL : MongoDB, Redis, Cassandra… ● Autour de la webapp ○ Forge logicielle en Java - Test-driven development ● Examen et exposées des projets
  • 3. Introduction Because I love to tell old stories
  • 4. Warning : I’m a web developer And when I tell stories, I do it from the webdev POV So please, thick-client devs, allow me some oversimplifications Image : TylkoMrok.pl
  • 5. At the beginning we had the thick client ● Widget : basic building blocks of your UI ○ Encapsulation ○ Reutilisation In thick client you create your UI by assembling widgets Image : Wikipedia
  • 6. Web development was unlike thick- client ● HTML/CSS/JS didn't support widgets ○ Pages were the building blocks Web apps were page oriented Image : IBM
  • 7. GWT gave back widgets to web devs ● GWT used a thick-client-like development paradigm ○ Widgets, properties, events GWT web apps were widget oriented : Single-page apps Image : GWT Mail sample app
  • 8. Single-page apps are a current trend ● From UX POV single-page apps are richer ○ But making them without widgets is risky and difficult HTML/CSS/JS needed a widget standard Image : Ken Schultz comedy juggler
  • 9. Web Components Reinventing the wheel... and this time making it round
  • 10. Example : the Google+ button ● If you want to place a Google+ button in your page <!-- Place this tag where you want the +1 button to render. --> <div class="g-plusone" data-annotation="inline" data-width="300" ></div> <!-- Place this tag after the last +1 button tag. --> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script>
  • 11. Example : the Google+ button ● And what I would like is simple <g:plusone></g:plusone>
  • 12. Example : the Google+ button ● To be fair, Google already makes it simpler <script type="text/javascript" src="https://apis.google.com/js/plusone.js"> </script>... <g:plusone></g:plusone> ● They create directives with JS to emulate components ○ AngularJS approach ○ Respecting the spirit of the future standard ○ Working in current browsers Totally non standard...
  • 13. Another example : the RIB ● If you're French, you know what a RIB is ○ A banking account identification number ● To show a RIB in HTML: ○ All styling & surface control must be done elsewhere by CSS and JS ● What I would like ○ A semantic tag ○ With encapsulated styling and surface controlling <div class="rib">58496 87451 00014500269 74</div> <x-rib banque="58496" guichet="87451" compte="00014500269" cle="74" />
  • 14. But we already can do that! ● In most modern frameworks we can already do components, in a way or another ○ And all those ways are different! ○ Using different JavaScript libraries ○ Almost no component sharing between frameworks ● W3C's works aim to make a standard way ○ Supported natively by all browsers ○ Allowing for component reuse
  • 15. Web Components : a W3C standard ● Web Components standard is being worked at W3C ○ We all know what this means ■ Clue : HTML5 They will work for years, bickering and fighting Browsers and devs will use the WiP document
  • 16. The 4 pillars of the Web Components ● Templates ● Shadow DOM ● Custom Elements ● Imports
  • 18. Templates before <template> ● How did we do templating before ○ Using display:none or hidden ○ Putting it inside a script ■ Type unknown to browser, it isn't interpreted ■ Markup easily recovered via .innerHTML and reused ■ Approach used by many template engines <div id="commentTemplate" class="comment" hidden> <img src=""> <div class="comment-text"></div> </div> <script id="commentTemplate" type="text/template"> <div class="comment"> <img src=""> <div class="comment-text"></div> </div> </script>
  • 19. ● Uniformising those approach with a new tag ● Content inside the tag is parsed but not interpreted ○ HTML not shown ○ Resources are not loaded ○ Scripts not executed The <template> tag <template id="commentTemplate"> <div> <img src=""> <div class="comment-text"></div> </div> </template>
  • 20. Template instantiation ● Create the elements in page by cloning the template <template id="commentTemplate"> <div class="comment"> <img src=""> <div class="comment-text"></div> </div> </template> <script> function addComment(imageUrl, text) { var t = document.querySelector("#commentTemplate"); var comment = t.content.cloneNode(true); // Populate content. comment.querySelector('img').src = imageUrl; comment.querySelector('.comment-text').textContent = text; document.body.appendChild(comment); } </script>
  • 21. Shadow DOM Image: Springfield Punx Join the shadowy side, young padawan
  • 22. Encapsulation ● Each component should have ○ Public interface ○ Private inner code ● When using a component ○ You manipulate the interface only ○ You don't need to know anything about inner code ○ No conflict between inner code and outside code
  • 23. Encapsulation before Shadow DOM ● Only a way : <innerFrame> Image : Star Trek the Next Generation
  • 24. Your browser cheats on you ● Considerer this simple slider ○ How does the browser deal with it? ■ With HTML, CSS and JS! ○ It has a movable element, I can recover it's position ■ Why cannot see it in DOM tree? Browsers hide DOM sub-trees for standard components They have a public interface and hidden inner code That's Shadow DOM! <input id="foo" type="range"> <video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> </video>
  • 25. My name is DOM, Shadow DOM ● Shadow DOM: ability of the browser to ○ Include a DOM subtree into the rendering ○ But not into the main document DOM tree ● In Chome you can see the Shadow DOM ○ By activating the option in Inspector
  • 26. Looking into the Shadow ● For the slider :
  • 27. Shadow DOM is already here ● Browser use it everyday... ○ For their inner needs ○ Not exposed to developers ● Web Components makes Shadow DOM available ○ You can use it for your own components Image: Springfield Punx
  • 28. Using Shadow DOM ● There is a host element ○ A normal element in DOM tree ● A shadow root is associated to the host ○ Using the createShadowRoot method ○ The shadow root is the root of the hidden DOM tree Image: W3C
  • 29. Using Shadow DOM ● Quick and dirty Shadow DOM ○ DOM tree only shows <div id="emptyHost"></div> ○ Rendered HTML shows Not empty anymore! ○ Markup in innerHTML is ugly <div id="emptyHost"></div> <script> var host = document.querySelector('#emptyHost'); var root = host.createShadowRoot(); root.innerHTML = "<h1>Not empty anymore!</h4>"; </script>
  • 30. Using Shadow DOM ● Shadow DOM with templates <div id="emptyHost"></div> <template id="commentTemplate"> [...] </template> <script> var host = document.querySelector('#emptyHost'); var shadowRoot = host.webkitCreateShadowRoot(); function addComment(imageUrl, text) { [...] } function addShadowedElement() { var instanceTemplate = addComment("http://lostinbrittany.org/avatar.png", "This is a nice comment made by a nice guy"); shadowRoot.appendChild(instanceTemplate); } </script>
  • 31. ● CSS defined in the Shadow DOM remains there ● Outside styles don't affect Shadowed content This is a title And this is widget title Widget content here Shadow DOM et CSS <h1>This is a title</h1> <div id="widget"> #document-fragment <style> div {border: solid 1px red;} h1 {color: blue;} </style> <h1>And this is widget title</h1> <div>Widget content here</div> </div>
  • 32. Shadow DOM et CSS ● Styling the host element : @host <template id="template"> <style> @host { button { border-radius: 5px; } } </style> <content></content> </template> <button id="host">My Button</button> <script> var host = document.querySelector('#host'); var root = host.createShadowRoot(); var shadowContent = document.querySelector("#template").content.cloneNode(true); root.appendChild(shadowContent); </script> My Button
  • 34. Image: The Brick Blogger Elemental mayhem ! Elemental mayhem !
  • 35. Custom elements : the HTML side ● An element encloses template, lifecycle and behaviour ○ Templates done with <template> tag <!-- Template Definition --> <template id="template"> <style> ... </style> <div id="container"> <img src="http://webcomponents.org/img/logo.svg"> <content select="h1"></content> </div> </template> <!-- Custom Element usage --> <x-component> <h1>This is Custom Element</h1> </x-component>
  • 36. Custom elements: the JavaScript side ● An element encloses template, lifecycle and behaviour ○ JavaScript to define behaviour and register the element var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { // Adding a Shadow DOM var root = this.createShadowRoot(); // Adding a template var template = document.querySelector('#template'); var clone = document.importNode(template.content, true); root.appendChild(clone); } var XComponent = document.registerElement('x-component', { prototype: proto });
  • 37. Extending other elements ● To create element A that extends element B, element A must inherit the prototype of element B var MegaButton = document.registerElement('mega-button', { prototype: Object.create(HTMLButtonElement.prototype), extends: 'button' });
  • 39. ● Custom elements can be loaded from external files ○ Using the link tag: ○ Only <decorator> and <element> are interpreted ○ The DOM of this document is available to script ○ Documents are retrieved according to cross-origin policies Imports <link rel="import" href="goodies.html">
  • 40. Can I use? Image: Christoph Hauf If not, why are you telling us all this sh*t?
  • 44. ● A Google project ○ Introduced in Google I/O 2013 ○ New type of library for the web ○ Built on top of Web Components ○ Designed to leverage the evolving web platform Version 1.0 released at Google IO 2015 Oh yeah! Polymer
  • 45. ● What does it means ? ○ Polymer is comprised of two efforts : ■ A paper platform to give Web Component capabilities to modern browsers ● Shims for all modern browsers ● Shared with Mozilla x-tag project ■ A next-generation web framework built upon this core platform ● Called Polymer Elements Polymer
  • 48. ● Principes: ○ Everything is a component ■ Encapsulation is needed for a component oriented application ○ Extreme pragmatism ■ Boilerplate is bad ■ Anything repetitive should be re-factored into a component ● Handled by Polymer itself or ● Added into the browser platform itself Polymer
  • 49. ● Principes: ○ Salt to taste ■ Use as much or as little of the framework as you wish. ● You want polyfills only : load polymer-all/platform/platform.js ● You want extra bits : load polymer-all/polymer/polymer.js ○ Polymer elements Polymer
  • 50. ● Platform technologies are already functional ○ You can use it to add templates, shadow DOM, custom elements and imports to your app ● Lots of examples in the site Polymer
  • 51. ● X-Tag is a small JavaScript library ○ created and supported by Mozilla ○ that brings Web Components capabilities ○ to all modern browsers ● Polymer vs X-Tag? ○ Different features and approaches ○ Mozilla and Google are collaborating ■ building the shared polyfills platform What about X-Tag?
  • 52. ● AngularJS directives allow to create custom elements ○ Same spirit, different implementation And AngularJS? <!doctype html> <html> <head> <title>Directive Test</title> <script type="text/javascript" src="jquery.min.js" ></script> <script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="mydirectives.js"></script> </head> <body ng-app> <div test-elem></div> </body> </html>
  • 53. Polymer today Because you can already play!
  • 54. Step-1 : get Polymer
  • 55. Step 2 - Use an element <!-- 1. Polyfill Web Components support for older browsers --> <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js" ></script> <!-- 2. Import element --> <link rel="import" href="bower_components/google-map/google-map.html"> <!-- 3. Use element --> <google-map latitude="47.205403" longitude="-1.5631069" zoom="17"></google-map>
  • 56. Step-3.1 : define an element <dom-module name="x-web2day"> <template> <style> @host { /*...*/ } </style> <div id="box"> <h1>Bonsoir web2day !</h1> <p><content></content></p> </div> </template> </dom-module> <script> Polymer({ is: 'x-web2day'}); </script>
  • 57. Step-3.2 : load Polymer, import your element <!DOCTYPE html> <html> <head> <!-- 1. Load Polymer --> <script src="bower_components/webcomponentsjs/webcomponents.js"> </script> <!-- 2. Load a component --> <link rel="import" href="x-web2day.html"> </head> <body> <!-- 3. Declare the component by its tag. --> <x-web2day>Et je peux mettre mon texte ici </x-web2day> </body> </html>
  • 59. Step-4.1 : Add properties/methods <dom-module id="x-web2day"> <template> <style> /.../ </style> <div id="box"> <h1>{{greet}}</h1> <p><content></content></p> <div><button on-click="alertHello">Click me!</button></div> </div> </template> </dom-module> <script> Polymer({ is: 'x-web2day', properties: { whoami: { type: String, value: "web2day" }, greet: { type: String, computed: 'doGreet(whoami)' } }, alertHello: function() { alert("Hello "+this.whoami);}, doGreet: function(who) { return "Hello "+who} }); </script>
  • 61. Step-4.1 : Two-ways databinding <dom-module id="x-web2day"> <template> <style>/*...*/</style> <div id="box"> <h1>Bonjour <span>{{whoami}}</span></h1> <p><content></content></p> <!-- iron-input exposes a two-way bindable input value --> <input is="iron-input" bind-value="{{whoami}}" placeholder="Your name here..." /> </div> </template> </dom-module> <script> Polymer({ is: 'x-web2day', properties: { whoami: { type: String, value: "web2day", notify: true } } }); </script>
  • 64. Polymer iron elements Set of visual and non-visual utility elements
  • 66. Paper Elements Image: ToyPro Material Design on Polymer, oh yeah!
  • 67. Android Lollipop's look & feel Material Design is a visual language that synthesizes the classic principles of good design with the innovation and possibility of technology and science It'slike a flat design,butin 3D! Nicevisualeffects!
  • 68. Material Design Visual language joining good design with technical innovation to create an unified experience across platforms and device sizes Responsive! Responsive!
  • 69. What's material design? http://www.google.com/design/spec/material-design/ UIs implementing a 3D metaphor : lights & shadows, stacking
  • 70. Polymer paper elements Set of visual elements that implement Material Design
  • 72. <paper-header-panel> <link rel=“import” href=“paper-toolbar.html”> <link rel=“import” href=“paper-header-panel.html”> <paper-header-panel flex> <paper-toolbar> <paper-icon-button icon=“menu"> </paper-icon-button> <div>I/O 2014</div> </paper-toolbar> <div class=“content”>…</div> </paper-header-panel>
  • 73. Elements are configurable <paper-header-panel mode=“scroll” flex> <paper-toolbar> <paper-icon-button icon=“menu"> </paper-icon-button> <div>I/O 2014</div> </paper-toolbar> <div class=“content”>…</div> </paper-header-panel> Toolbar will scroll with the page
  • 74. Responsivity from the beginning <paper-drawer-panel> <div drawer> Drawer panel… </div> <div main> Main panel... </div> </paper-drawer-panel>
  • 75. <paper-ripple> <div class=“card”> <img src=“learning.svg”> <paper-ripple fit></paper-ripple> </div> <div class=“card”> <img src=“science.svg”> <paper-ripple fit></paper-ripple> </div> <div class=“card”> <img src=“food.svg”> <paper-ripple fit></paper-ripple> </div> <div class=“card”> <img src=“earth.svg”> <paper-ripple fit></paper-ripple> </div> A reactive ink effect for indicating touch and mouse actions
  • 76. A full demo of Polymer Paper https://www.polymer-project.org/apps/topeka/
  • 78. Gold Elements Image: Pinterest For e-commerce use-cases
  • 79. Polymer gold elements Set of elements for e-commerce use-cases, like checkout flows
  • 80. Google Web Components Image: LikeCool From widgets to full apps
  • 81. Google Web Components From small widgets to full-scoped apps
  • 82. Other available web components Image: KNP Labs The more, the merrier!
  • 86. You want to know more? ● W3C's Introduction to Web Components ● HTML5 Rocks' Shadow DOM 101 & HTML5 Rocks' Shadow DOM 201: CSS ● WebComponents.org's Introduction to Shadow DOM ● Polymer, X-Tags, Mozilla Brick ● MutationObserver & Object.observe