SlideShare a Scribd company logo
1
Web Components
It's all rainbows and
unicorns! Is it?
Sara HARKOUSSE
UNITED DEV CONF
Minsk, 6,7 April 2017
http://vignette2.wikia.nocookie.net/weirdcommunity/images/a/a2/Rainbow-flow-abstract-backgrounds-for-powerpoint.jpg/revision/latest?cb=20130603085532​​ 2
SARA HARKOUSSE
@Sara_harkousse
Tech Lead, front-end Web developer at Dassault Systèmes
3D design & PLM software
Electronics and Computer Science Engineer by training
About me
@UnitedDevConf #webcomponents
3
Women in Tech
Duchess France
@duchessfr
duchess-france.org
Elles bougent (Girls on The Move)
@ellesbougent
ellesbougent.com
@UnitedDevConf #webcomponents @Sara_harkousse
4
Web Components
It's all rainbows and
unicorns! Is it?
http://vignette2.wikia.nocookie.net/weirdcommunity/images/a/a2/Rainbow-flow-abstract-backgrounds-for-powerpoint.jpg/revision/latest?cb=20130603085532​​ 5
"The web components revolution"
"A Tectonic shift for web development"
"Web components are a game changer"
Web components'
public image
@UnitedDevConf #webcomponents @Sara_harkousse
6
Outline of this talk
@UnitedDevConf #webcomponents @Sara_harkousse
Motivation
Refresher on web components
Dive deep
Concluding remarks
7
Motivation
@UnitedDevConf #webcomponents @Sara_harkousse
Modular architecture
Filterable
Product Table
Search Bar Product Table
Product
Row
Product
Category
Row
https://facebook.github.io/react/docs/thinking-in-react.html
8
@UnitedDevConf #webcomponents @Sara_harkousse
Angular 4.0 Component
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>`
})
export class AppComponent { name = 'Angular'; }
<my-app><h1>Hello Angular</h1></my-app>
https://embed.plnkr.co/?show=preview&show=app%2Fapp.component.ts
9
@UnitedDevConf #webcomponents @Sara_harkousse
Ember 2.12.0 Component
<article class="blog-post">
<h1>{{title}}</h1>
<p>{{yield}}</p>
<p>Edit title: {{input type="text" value=title}}</p>
</article>
{{#each model as |post|}}
{{#blog-post title=post.title}}
{{post.body}}
{{/blog-post}}
{{/each}}
https://guides.emberjs.com/v2.12.0/components/defining-a-component/
10
@UnitedDevConf #webcomponents @Sara_harkousse
Polymer 2.0 Element
// Define the class for a new element called custom-element
class CustomElement extends Polymer.Element {
static get is() { return "custom-element"; }
constructor() {
super();
this.textContent = "I'm a custom-element.";
}
}
// Register the new element with the browser
customElements.define(CustomElement.is, CustomElement);
<custom-element></custom-element>
http://plnkr.co/edit/PaCt2M?p=preview
11
@UnitedDevConf #webcomponents @Sara_harkousse
Frameworks make it
hard to get along
12
@UnitedDevConf #webcomponents @Sara_harkousse
Harmony happens
when there is less
learning curve
13
@UnitedDevConf #webcomponents @Sara_harkousse
Browser support
https://www.webcomponents.org/
use webcomponents.js
14
Refresher on web
components
@UnitedDevConf #webcomponents @Sara_harkousse
HTML Template Tag
HTML Imports
Custom Elements
Shadow DOM
15
HTML Template Tag
@UnitedDevConf #webcomponents @Sara_harkousse
<template id="template">
<div id="container">
<img class="webcomponents" src="https://webcomponents/imgs/webcomponents-logo.svg">
</div>
</template>
https://jsfiddle.net/sara_harkousse/rnu8zc0c/
16
HTML Template Tag Usage
@UnitedDevConf #webcomponents @Sara_harkousse
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
var host = document.querySelector('#host');
host.appendChild(clone);
https://jsfiddle.net/sara_harkousse/rnu8zc0c/
17
Template Tag drawbacks?
@UnitedDevConf #webcomponents @Sara_harkousse
18
HTML Template Tag
@UnitedDevConf #webcomponents @Sara_harkousse
A way to add inert DOM elements to your
document
Not something that's going to revolutionize your
apps
No two-way data binding, no binding at all
19
HTML Imports
@UnitedDevConf #webcomponents @Sara_harkousse
<link rel="import" href="/imports/productRow.html">
<script src="js/productRow.js"></script>
<template>
<!-- content-->
<template>
20
How to get my
component?
@UnitedDevConf #webcomponents @Sara_harkousse
var link = document.querySelector('link[rel="import"]');
var content = link.import;
// Grab DOM from productRow.html's document.
var el = content.querySelector('.productRow');
document.body.appendChild(el.cloneNode(true));
21
Why not this way?
@UnitedDevConf #webcomponents @Sara_harkousse
var el = require('/imports/productRow');
22
@UnitedDevConf #webcomponents @Sara_harkousse
<!doctype html>
<html lang="en">
<head>
<link rel="import" href="/imports/productRow.html">
</head>
<body>
<!-- index content -->
</body>
</html>
Render blocking
23
@UnitedDevConf #webcomponents @Sara_harkousse
<!doctype html>
<html lang="en">
<head>
<link rel="import" href="/imports/productRow.html" async>
</head>
<body>
<!-- index content -->
</body>
</html>
async unblocks the renderer
24
@UnitedDevConf #webcomponents @Sara_harkousse
Hammering our
server
Each one of the HTML imports is another
XMLHttpRequest
25
@UnitedDevConf #webcomponents @Sara_harkousse
Build tools for HTML
Import
e.g. Vulcanizr (turns all imports into one
import)
26
@UnitedDevConf #webcomponents @Sara_harkousse
HTML Import
requires a polyfill
ES6 module?
Note: polyfill doesn’t work with file:/// protocols because it
does a hidden XMLHttpRequest.
https://www.webcomponents.org/
27
@UnitedDevConf #webcomponents @Sara_harkousse
Shadow DOM
A tiny document
exists inside of a host element
28
@UnitedDevConf #webcomponents @Sara_harkousse
Key concepts
Isolated DOM
Scoped CSS
Rendering of shadow tree replaces that
of host tree
29
@UnitedDevConf #webcomponents @Sara_harkousse
Number of shadow
trees
How many shadow trees are too many?
30
@UnitedDevConf #webcomponents @Sara_harkousse
What's inside the
Shadow DOM?
What to put in the Shadow DOM and what not to?
<my-app>
31
@UnitedDevConf #webcomponents @Sara_harkousse
Shadow DOM
requires a polyfill
Hard to polyfill
32
@UnitedDevConf #webcomponents @Sara_harkousse
Use/Don't
use
Shadow
DOM?
callback() {
// Use it
this.root = this.attachShadow({mode: 'open'});
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
this.root.appendChild(clone);
}
callback() {
// Don't Use it
this.root = this;
var template = document.querySelector('#template');
var clone = document.importNode(template.content, true);
this.root.appendChild(clone);
}
33
@UnitedDevConf #webcomponents @Sara_harkousse
Use/Don't use
Shadow DOM?
/* Use it */
:host {
color: red;
}
/* Don't use it */
custom-component {
color: red;
}
34
@UnitedDevConf #webcomponents @Sara_harkousse
Use AND Don't use
Shadow DOM
if (shadowflag){
this.root = this.attachShadow({mode: 'open'});
} else {
this.root = this;
}
custom-component, :host {
color: red;
}
35
@UnitedDevConf #webcomponents @Sara_harkousse
Custom Elements
class UnitedDevConButton extends HTMLElement {...}
window.customElements.define('unitedDevCon-button', UnitedDevConButton);
<unitedDevCon-button></unitedDevCon-button>
Acts like a div
36
@UnitedDevConf #webcomponents @Sara_harkousse
Custom Elements
class UnitedDevConButton extends HTMLButtonElement {...}
window.customElements.define('unitedDevCon-button', UnitedDevConButton, {extends: 'button'});
<button is="unitedDevCon-button" disabled>My button!</button>
Acts like a real button
37
@UnitedDevConf #webcomponents @Sara_harkousse
Custom Elements
Namespace
Dash (-) rule
38
@UnitedDevConf #webcomponents @Sara_harkousse
Custom Elements
ES6 Class
class UnitedDevCon-component extends HTMLElement {
constructor() {
super(); // always call super() first in the ctor.
...
}
connectedCallback() {
...
}
disconnectedCallback() {
...
}
attributeChangedCallback(attrName, oldVal, newVal) {
...
}
}
39
@UnitedDevConf #webcomponents @Sara_harkousse
Component example
Bootstrap Progress Bar
<div class="progress">
<div class="progress-bar" style="width: 60%;">
60%
</div>
</div>
40
@UnitedDevConf #webcomponents @Sara_harkousse
Component example
class ProgressBar extends HTMLElement {
constructor() {
super(); // always call super() first in the ctor.
this.shadow = this.attachShadow({mode: 'open'});
this._complete = 0;
}
get complete() {
return this._complete;
}
set complete(val) {
this.setAttribute('complete', val);
}
}
https://jsfiddle.net/sara_harkousse/kwwe75yy/
41
@UnitedDevConf #webcomponents @Sara_harkousse
class ProgressBar extends HTMLElement {
static get observedAttributes() {
return ['complete'];
}
attributeChangedCallback(name, oldval, newval) {
// code
}
}
https://jsfiddle.net/sara_harkousse/kwwe75yy/
Component example
42
@UnitedDevConf #webcomponents @Sara_harkousse
class ProgressBar extends HTMLElement {
attributeChangedCallback(name, oldval, newval) {
var innerBar = this.shadow.querySelector('.progress-bar-inner');
switch(name) {
case 'complete':
this._complete = parseInt(newval, 10) || 0;
innerBar.style.width = this.complete + '%';
innerBar.innerHTML = this.complete + '%';
}
}
}
https://jsfiddle.net/sara_harkousse/kwwe75yy/
Component example
43
@UnitedDevConf #webcomponents @Sara_harkousse
class ProgressBar extends HTMLElement {
connectedCallback() {
var template = `<style>
.progress-bar {
width: 50%;
...
}
.progress-bar-inner {
height: 100%;
....
}
</style>
<div class="progress-bar">
<div class="progress-bar-inner">${this.complete}%</div>
</div>`;
this.shadow.innerHTML = template;
}
}
https://jsfiddle.net/sara_harkousse/kwwe75yy/
Component example
44
@UnitedDevConf #webcomponents @Sara_harkousse
window.customElements.define('progress-bar', ProgressBar);
// Use
<progress-bar></progress-bar>
Component example
45
@UnitedDevConf #webcomponents @Sara_harkousse
Components
on a page
<!doctype html>
<html lang="en">
<head>
<link rel="import" href="/imports/productRow.html">
</head>
<body>
<custom-navbar style="compact"></custom-navbar>
<custom-toolbar style="full"></custom-toolbar>
<custom-pagecontent>
<custom-item attr="val"></custom-item>
<custom-input attr="val"></custom-input>
<progress-bar></progress-bar>
</custom-pagecontent>
<script>
document.querySelector('progress-bar').addEventListener(
'customevent', function () {
// do something
}
});
</script>
</body>
</html>
46
@UnitedDevConf #webcomponents @Sara_harkousse
General concerns
Should you load the polyfills in
every bowser? No.
47
@UnitedDevConf #webcomponents @Sara_harkousse
var = webComponentsSupported = ('customElements' in window
&& !!HTMLElement.prototype.attachShadow
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template'));
function loadScript(src) {
return new Promise(function(resolve, reject) {
const script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}
// Lazy load the polyfill if necessary.
if (!supportsCustomElementsV1) {
loadScript('webcomponents-lite.min.js').then(e => {
// Polyfill loaded.
});
} else {
// Native support. Good to go.
}
48
@UnitedDevConf #webcomponents @Sara_harkousse
Complex
documentation
not fun documents to read
49
@UnitedDevConf #webcomponents @Sara_harkousse
Takeaway
You will understand some of the design decisions of
major frameworks if you learn about custom
elements
50
@UnitedDevConf #webcomponents @Sara_harkousse
Takeaway
Who is using web components?
51
@UnitedDevConf #webcomponents @Sara_harkousse
Takeaway
GitHub Mozilla VR Google
52
@UnitedDevConf #webcomponents
Thanks for listening!
Follow for slides
@Sara_harkousse
53

More Related Content

PDF
Звиад Кардава "Android Things + Google Weave"
PDF
Java REST API Framework Comparison - PWX 2021
PDF
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
PDF
Node.js Authentication and Data Security
PDF
State of the resource timing api
PDF
Bootiful Development with Spring Boot and React - UberConf 2018
PDF
A Gentle Introduction to Angular Schematics - Angular SF 2019
PDF
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019
Звиад Кардава "Android Things + Google Weave"
Java REST API Framework Comparison - PWX 2021
Visual Component Testing -- w/ Gil Tayar (Applitools) and Gleb Bahmutov (Cyp...
Node.js Authentication and Data Security
State of the resource timing api
Bootiful Development with Spring Boot and React - UberConf 2018
A Gentle Introduction to Angular Schematics - Angular SF 2019
A Gentle Introduction to Angular Schematics - Devoxx Belgium 2019

What's hot (20)

PPTX
JavaScript Performance (at SFJS)
PDF
What Web Developers Need to Know to Develop Windows 8 Apps
PDF
Vaadin Components @ Angular U
PDF
Front End Development for Back End Developers - vJUG24 2017
PDF
Usability in the GeoWeb
PDF
Vaadin Components
PDF
Hybrid Apps (Native + Web) via QtWebKit
PPT
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
PDF
Front End Development for Back End Developers - Denver Startup Week 2017
PDF
Front End Development for Backend Developers - GIDS 2019
PDF
Android Data Binding in action using MVVM pattern - droidconUK
PPT
Widget Summit 2008
PPT
AngularJS for Legacy Apps
PDF
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
PPT
Choosing a Java Web Framework
PPT
Os Johnson
PDF
Bootiful Development with Spring Boot and React - RWX 2017
PPTX
Using Components to Build Native-Quality HTML5 Apps
PDF
A realtime infrastructure for Android apps: Firebase may be what you need..an...
PDF
Clojure Web Development
JavaScript Performance (at SFJS)
What Web Developers Need to Know to Develop Windows 8 Apps
Vaadin Components @ Angular U
Front End Development for Back End Developers - vJUG24 2017
Usability in the GeoWeb
Vaadin Components
Hybrid Apps (Native + Web) via QtWebKit
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Backend Developers - GIDS 2019
Android Data Binding in action using MVVM pattern - droidconUK
Widget Summit 2008
AngularJS for Legacy Apps
Spring Boot APIs and Angular Apps: Get Hip with JHipster! KCDC 2019
Choosing a Java Web Framework
Os Johnson
Bootiful Development with Spring Boot and React - RWX 2017
Using Components to Build Native-Quality HTML5 Apps
A realtime infrastructure for Android apps: Firebase may be what you need..an...
Clojure Web Development
Ad

Similar to Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?" (20)

PDF
Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE
PDF
Web components the future is here
PPTX
Web Components: Introduction and Practical Use Cases
PPT
Reaching for the Future with Web Components and Polymer
PPTX
Web Components
PDF
Web component driven development
PPTX
User-Customizable Web Components for Building One-Page Sites
PDF
KharkivJS: Flaws of the Web Components in 2019 and how to address them
PDF
Frameworks and webcomponents
PPTX
Introduction to Web Components & Polymer Workshop - U of I WebCon
PPTX
Web Components: The Future of Web Development is Here
PDF
Web components: A simpler and faster react
PDF
Real World Web components
PPTX
Web components Introduction
PDF
Lit there be light
PDF
Webcomponents are your frameworks best friend
PDF
«Разрушаем Вавилонскую Башню WWW с помощью веб-компонент»​
PDF
Front-end tower of Babylon
PPTX
Magic of web components
PDF
Web Components - The Future is Here
Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE
Web components the future is here
Web Components: Introduction and Practical Use Cases
Reaching for the Future with Web Components and Polymer
Web Components
Web component driven development
User-Customizable Web Components for Building One-Page Sites
KharkivJS: Flaws of the Web Components in 2019 and how to address them
Frameworks and webcomponents
Introduction to Web Components & Polymer Workshop - U of I WebCon
Web Components: The Future of Web Development is Here
Web components: A simpler and faster react
Real World Web components
Web components Introduction
Lit there be light
Webcomponents are your frameworks best friend
«Разрушаем Вавилонскую Башню WWW с помощью веб-компонент»​
Front-end tower of Babylon
Magic of web components
Web Components - The Future is Here
Ad

More from IT Event (20)

PDF
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
PDF
Max Voloshin - "Organization of frontend development for products with micros...
PDF
Roman Romanovsky, Sergey Rak - "JavaScript в IoT "
PDF
Konstantin Krivlenia - "Continuous integration for frontend"
PPTX
Illya Klymov - "Vue.JS: What did I swap React for in 2017 and why?"
PDF
Evgeny Gusev - "A circular firing squad: How technologies drag frontend down"
PDF
Vladimir Grinenko - "Dependencies in component web done right"
PDF
Dmitry Bartalevich - "How to train your WebVR"
PDF
Aleksey Bogachuk - "Offline Second"
PDF
James Allardice - "Building a better login with the credential management API"
PDF
Fedor Skuratov "Dark Social: as messengers change the market of social media ...
PPTX
Андрей Зайчиков "Архитектура распределенных кластеров NoSQL на AWS"
PPTX
Алексей Рагозин "Java и linux борьба за микросекунды"
PPTX
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
PDF
Наш ответ Uber’у
PDF
Александр Крашенинников "Hadoop High Availability: опыт Badoo"
PDF
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
PDF
Анатолий Пласковский "Миллионы карточных платежей за месяц, или как потерять ...
PDF
Mete Atamel "Resilient microservices with kubernetes"
PDF
Andrew Stain "User acquisition"
Denis Radin - "Applying NASA coding guidelines to JavaScript or airspace is c...
Max Voloshin - "Organization of frontend development for products with micros...
Roman Romanovsky, Sergey Rak - "JavaScript в IoT "
Konstantin Krivlenia - "Continuous integration for frontend"
Illya Klymov - "Vue.JS: What did I swap React for in 2017 and why?"
Evgeny Gusev - "A circular firing squad: How technologies drag frontend down"
Vladimir Grinenko - "Dependencies in component web done right"
Dmitry Bartalevich - "How to train your WebVR"
Aleksey Bogachuk - "Offline Second"
James Allardice - "Building a better login with the credential management API"
Fedor Skuratov "Dark Social: as messengers change the market of social media ...
Андрей Зайчиков "Архитектура распределенных кластеров NoSQL на AWS"
Алексей Рагозин "Java и linux борьба за микросекунды"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Наш ответ Uber’у
Александр Крашенинников "Hadoop High Availability: опыт Badoo"
Leonid Vasilyev "Building, deploying and running production code at Dropbox"
Анатолий Пласковский "Миллионы карточных платежей за месяц, или как потерять ...
Mete Atamel "Resilient microservices with kubernetes"
Andrew Stain "User acquisition"

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.

Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"