SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Web Components
It's all rainbows and
unicorns! Is it?
Sara HARKOUSSE
BlendWebMix
Lyon, 26, 27 October 2017
1
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
#BlendWebMix #webcomponents 2
Women in Tech
Duchess France
@duchessfr
duchess-france.org
Elles bougent (Girls on The Move)
@ellesbougent
ellesbougent.com
#BlendWebMix #webcomponents @Sara_harkousse 3
Web Components
It's all rainbows and
unicorns! Is it?
4
"The web components revolution"
"A Tectonic shift for web development"
"Web components are a game changer"
Web components'
public image
#BlendWebMix #webcomponents @Sara_harkousse 5
Web components'
public image
#BlendWebMix #webcomponents @Sara_harkousse
"The broken promise of Web Components"
6
Motivation
#BlendWebMix #webcomponents @Sara_harkousse
Modular architecture
Filterable
Product Table
Search Bar Product Table
Product
Row
Product
Category
Row
7
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
#BlendWebMix #webcomponents @Sara_harkousse
Ember 2.16.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/
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
8
#BlendWebMix #webcomponents @Sara_harkousse
Frameworks make it
hard to get along
9
#BlendWebMix #webcomponents @Sara_harkousse
Harmony happens
when there is less
learning curve
10
Browser support
use webcomponents.js
#BlendWebMix #webcomponents @Sara_harkousse 11
Refresher on web
components
Web components are a set of web platform APIs
that allow you to create new custom, reusable,
encapsulated HTML tags to use in web apps.”
#BlendWebMix #webcomponents @Sara_harkousse 12
Refresher on web
components
#BlendWebMix #webcomponents @Sara_harkousse
HTML Template Tag
HTML Imports
Custom Elements
Shadow DOM
13
HTML Template Tag
#BlendWebMix #webcomponents @Sara_harkousse
<template id="template">
<div id="container">
<img class="webcomponents" src="logo.svg">
</div>
</template>
14
HTML Template Tag Usage
#BlendWebMix #webcomponents @Sara_harkousse
var template = document.querySelector('#template');
var clone = template.content.cloneNode(true);
var host = document.querySelector('#host');
host.appendChild(clone);
15
HTML Template Tag
#BlendWebMix #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
16
HTML Imports
#BlendWebMix #webcomponents @Sara_harkousse
<link rel="import" href="component.html">
<link rel="stylesheet" href="style.css">
<div id="container">
<img class="rotate" src="logo.svg">
</div>
<script src="script.js"></script>
17
How to get my
component?
#BlendWebMix #webcomponents @Sara_harkousse
var link = document.querySelector('link[rel="import"]');
var content = link.import;
// Grab DOM from component.html's document.
var el = content.querySelector('#container');
var clone = el.cloneNode(true);
var host = document.querySelector('#host');
host.appendChild(clone);
18
#BlendWebMix #webcomponents @Sara_harkousse
HTML Import
requires a polyfill
ES module?
19
#BlendWebMix #webcomponents @Sara_harkousse
ES module
// export feature
export const Component = // …
// import feature
import {Component} from '../components/cutom-component.js';
20
#BlendWebMix #webcomponents @Sara_harkousse
Shadow DOM
A tiny document
exists inside of a host element
21
#BlendWebMix #webcomponents @Sara_harkousse
Key concepts
Isolated DOM
Scoped CSS
22
#BlendWebMix #webcomponents @Sara_harkousse
Shadow DOM
requires a polyfill
Hard to polyfill
23
#BlendWebMix #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);
}
24
#BlendWebMix #webcomponents @Sara_harkousse
Use/Don't use
Shadow DOM?
/* Use it */
:host {
color: red;
}
/* Don't use it */
custom-component {
color: red;
}
25
#BlendWebMix #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;
}
26
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
class CustomButton extends HTMLElement {...}
window.customElements.define('custom-button', CustomButton);
<custom-button></custom-button>
Acts like a div
27
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
class CustomButton extends HTMLButtonElement {...}
window.customElements.define('custom-button', CustomButton, {extends: 'button'});
<button is="custom-button" disabled>My button!</button>
Acts like a real button
28
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
Namespace
Dash (-) rule
29
#BlendWebMix #webcomponents @Sara_harkousse
Custom Elements
ES6 Class
class Custom-component extends HTMLElement {
constructor() {
super(); // always call super() first in the ctor.
...
}
connectedCallback() {
...
}
disconnectedCallback() {
...
}
attributeChangedCallback(attrName, oldVal, newVal) {
...
}
}
30
#BlendWebMix #webcomponents @Sara_harkousse
Component example
Bootstrap Progress Bar
<div class="progress">
<div class="progress-bar" style="width: 60%;">
60%
</div>
</div>
31
window.customElements.define('progress-bar', ProgressBar);
// Use
<progress-bar></progress-bar>
Component example
https://jsfiddle.net/sara_harkousse/kwwe75yy/
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);
}
static get observedAttributes() {
return ['complete'];
}
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 + '%';
}
}
connectedCallback() {
var template = `<div class="progress-bar">
<div class="progress-bar-inner">${this.complete}%</div>
</div>`;
this.shadow.innerHTML = template;
}
}
#BlendWebMix #webcomponents @Sara_harkousse 32
#BlendWebMix #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-input attr="val"></custom-input>
<progress-bar></progress-bar>
</custom-pagecontent>
<script>
document.querySelector('custom-input').dispatchEvent(new CustomEvent('customevent', {
detail: { prop: true }
}));
document.querySelector('progress-bar').addEventListener(
'customevent', function () {
// do something
}
});
</script>
</body>
</html>
33
#BlendWebMix #webcomponents @Sara_harkousse
Takeaway
Template tag? yeah! why not?
Use ES module instead of HTML Imports
Use Shadom DOM with a flag
Custom Elements?? Go, Go, Go
34
#BlendWebMix #webcomponents @Sara_harkousse
Takeaway
You will understand some of the design decisions of
major frameworks if you learn about custom
elements
35
#BlendWebMix #webcomponents
Thanks for listening!
Follow for slides
@Sara_harkousse
https://github.com/SaraHarkousse
36

Weitere ähnliche Inhalte

Ähnlich wie Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE

Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"IT Event
 
Ensuring Design Standards with Web Components
Ensuring Design Standards with Web ComponentsEnsuring Design Standards with Web Components
Ensuring Design Standards with Web ComponentsJohn Riviello
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
Introduction to web components
Introduction to web componentsIntroduction to web components
Introduction to web componentsMarc Bächinger
 
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...Codemotion
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...Roni Banerjee
 
Polymer
Polymer Polymer
Polymer jskvara
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSSAndrew Rota
 
Polymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest FloridaPolymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest FloridaJohn Riviello
 
Things To Keep In Mind When Working In The World Of Responsive Design
Things To Keep In Mind When Working In The World Of Responsive DesignThings To Keep In Mind When Working In The World Of Responsive Design
Things To Keep In Mind When Working In The World Of Responsive DesignFITC
 
Conquering Code with hjc
Conquering Code with hjcConquering Code with hjc
Conquering Code with hjchjc
 
Design Systems, Pattern Libraries & WordPress
Design Systems, Pattern Libraries & WordPressDesign Systems, Pattern Libraries & WordPress
Design Systems, Pattern Libraries & WordPressJesse James Arnold
 
Fiverr html5 test answers 2020
Fiverr html5 test answers 2020Fiverr html5 test answers 2020
Fiverr html5 test answers 2020Roobon Habib
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with AngularAna Cidre
 
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Amazon Web Services
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump StartHaim Michael
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applicationsVittorio Vittori
 
The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014Tommie Gannert
 

Ähnlich wie Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE (20)

Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
Sara Harkousse - "Web Components: It's all rainbows and unicorns! Is it?"
 
Ensuring Design Standards with Web Components
Ensuring Design Standards with Web ComponentsEnsuring Design Standards with Web Components
Ensuring Design Standards with Web Components
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
Introduction to web components
Introduction to web componentsIntroduction to web components
Introduction to web components
 
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
“Good design is obvious. Great design is transparent.” — How we use Bootstrap...
 
Polymer
Polymer Polymer
Polymer
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Polymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest FloridaPolymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest Florida
 
Things To Keep In Mind When Working In The World Of Responsive Design
Things To Keep In Mind When Working In The World Of Responsive DesignThings To Keep In Mind When Working In The World Of Responsive Design
Things To Keep In Mind When Working In The World Of Responsive Design
 
Conquering Code with hjc
Conquering Code with hjcConquering Code with hjc
Conquering Code with hjc
 
Design Systems, Pattern Libraries & WordPress
Design Systems, Pattern Libraries & WordPressDesign Systems, Pattern Libraries & WordPress
Design Systems, Pattern Libraries & WordPress
 
Fiverr html5 test answers 2020
Fiverr html5 test answers 2020Fiverr html5 test answers 2020
Fiverr html5 test answers 2020
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
Expedite the development lifecycle with MongoDB and serverless - DEM02 - Sant...
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014The Structure of Web Code: A Case For Polymer, November 1, 2014
The Structure of Web Code: A Case For Polymer, November 1, 2014
 
The Devil and HTML5
The Devil and HTML5The Devil and HTML5
The Devil and HTML5
 

Mehr von La Cuisine du Web

Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...La Cuisine du Web
 
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...La Cuisine du Web
 
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...La Cuisine du Web
 
Tour d’horizon de l’écosystème React-ien par Guillaume BESSON
Tour d’horizon de l’écosystème React-ien par Guillaume BESSONTour d’horizon de l’écosystème React-ien par Guillaume BESSON
Tour d’horizon de l’écosystème React-ien par Guillaume BESSONLa Cuisine du Web
 
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARD
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARDStream processing en mémoire avec Hazelcast Jet par Claire VILLARD
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARDLa Cuisine du Web
 
Programming is Fun par Francis BELLANGER
Programming is Fun par Francis BELLANGERProgramming is Fun par Francis BELLANGER
Programming is Fun par Francis BELLANGERLa Cuisine du Web
 
La démarche communautaire au coeur de la croissance de votre entreprise par H...
La démarche communautaire au coeur de la croissance de votre entreprise par H...La démarche communautaire au coeur de la croissance de votre entreprise par H...
La démarche communautaire au coeur de la croissance de votre entreprise par H...La Cuisine du Web
 
Qui est ton client ? par Audrey JULIENNE
Qui est ton client ? par Audrey JULIENNEQui est ton client ? par Audrey JULIENNE
Qui est ton client ? par Audrey JULIENNELa Cuisine du Web
 
Cloaking is not a crime par Patrick VALIBUS
Cloaking is not a crime par Patrick VALIBUSCloaking is not a crime par Patrick VALIBUS
Cloaking is not a crime par Patrick VALIBUSLa Cuisine du Web
 
Electron, une alternative intéressante ? par Florent MOIGNARD
Electron, une alternative intéressante ? par Florent MOIGNARDElectron, une alternative intéressante ? par Florent MOIGNARD
Electron, une alternative intéressante ? par Florent MOIGNARDLa Cuisine du Web
 
CSS orienté objet par Lenny ROUANET
CSS orienté objet par Lenny ROUANETCSS orienté objet par Lenny ROUANET
CSS orienté objet par Lenny ROUANETLa Cuisine du Web
 
Automatiser la mise en production d’un site web par Nicolas KANDEL
Automatiser la mise en production d’un site web par Nicolas KANDELAutomatiser la mise en production d’un site web par Nicolas KANDEL
Automatiser la mise en production d’un site web par Nicolas KANDELLa Cuisine du Web
 
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANNDesign Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANNLa Cuisine du Web
 
Fontes variables, la matrice typographique par Malou VERLOMME
Fontes variables, la matrice typographique par Malou VERLOMMEFontes variables, la matrice typographique par Malou VERLOMME
Fontes variables, la matrice typographique par Malou VERLOMMELa Cuisine du Web
 
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...La Cuisine du Web
 
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...La Cuisine du Web
 
Audio procédural : la révolution WebAssembly ! par Yann ORLAREY
Audio procédural : la révolution WebAssembly ! par Yann ORLAREYAudio procédural : la révolution WebAssembly ! par Yann ORLAREY
Audio procédural : la révolution WebAssembly ! par Yann ORLAREYLa Cuisine du Web
 
A la rencontre de Kafka, le log distribué par Florian GARCIA
A la rencontre de Kafka, le log distribué par Florian GARCIAA la rencontre de Kafka, le log distribué par Florian GARCIA
A la rencontre de Kafka, le log distribué par Florian GARCIALa Cuisine du Web
 
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...La Cuisine du Web
 
Ciel mon smartphone ! par Damien GOSSET
Ciel mon smartphone ! par Damien GOSSETCiel mon smartphone ! par Damien GOSSET
Ciel mon smartphone ! par Damien GOSSETLa Cuisine du Web
 

Mehr von La Cuisine du Web (20)

Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
Kit de survie du marketeur au bois dormant – Digitalisation du marketing par ...
 
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
Objets connectés : adapter la technologie aux usages, et pas l’inverse ! par ...
 
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
Manager l’innovation : est-ce contradictoire, pertinent, nécessaire ?… par Ma...
 
Tour d’horizon de l’écosystème React-ien par Guillaume BESSON
Tour d’horizon de l’écosystème React-ien par Guillaume BESSONTour d’horizon de l’écosystème React-ien par Guillaume BESSON
Tour d’horizon de l’écosystème React-ien par Guillaume BESSON
 
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARD
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARDStream processing en mémoire avec Hazelcast Jet par Claire VILLARD
Stream processing en mémoire avec Hazelcast Jet par Claire VILLARD
 
Programming is Fun par Francis BELLANGER
Programming is Fun par Francis BELLANGERProgramming is Fun par Francis BELLANGER
Programming is Fun par Francis BELLANGER
 
La démarche communautaire au coeur de la croissance de votre entreprise par H...
La démarche communautaire au coeur de la croissance de votre entreprise par H...La démarche communautaire au coeur de la croissance de votre entreprise par H...
La démarche communautaire au coeur de la croissance de votre entreprise par H...
 
Qui est ton client ? par Audrey JULIENNE
Qui est ton client ? par Audrey JULIENNEQui est ton client ? par Audrey JULIENNE
Qui est ton client ? par Audrey JULIENNE
 
Cloaking is not a crime par Patrick VALIBUS
Cloaking is not a crime par Patrick VALIBUSCloaking is not a crime par Patrick VALIBUS
Cloaking is not a crime par Patrick VALIBUS
 
Electron, une alternative intéressante ? par Florent MOIGNARD
Electron, une alternative intéressante ? par Florent MOIGNARDElectron, une alternative intéressante ? par Florent MOIGNARD
Electron, une alternative intéressante ? par Florent MOIGNARD
 
CSS orienté objet par Lenny ROUANET
CSS orienté objet par Lenny ROUANETCSS orienté objet par Lenny ROUANET
CSS orienté objet par Lenny ROUANET
 
Automatiser la mise en production d’un site web par Nicolas KANDEL
Automatiser la mise en production d’un site web par Nicolas KANDELAutomatiser la mise en production d’un site web par Nicolas KANDEL
Automatiser la mise en production d’un site web par Nicolas KANDEL
 
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANNDesign Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
Design Sprints : Créons un monde meilleur ! par Jelto VON SCHUCKMANN
 
Fontes variables, la matrice typographique par Malou VERLOMME
Fontes variables, la matrice typographique par Malou VERLOMMEFontes variables, la matrice typographique par Malou VERLOMME
Fontes variables, la matrice typographique par Malou VERLOMME
 
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
Le design agile : 6 techniques pour designer de façon plus agile par Matthieu...
 
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
Réalité virtuelle et augmentée, ces nouvelles technologies au service de la f...
 
Audio procédural : la révolution WebAssembly ! par Yann ORLAREY
Audio procédural : la révolution WebAssembly ! par Yann ORLAREYAudio procédural : la révolution WebAssembly ! par Yann ORLAREY
Audio procédural : la révolution WebAssembly ! par Yann ORLAREY
 
A la rencontre de Kafka, le log distribué par Florian GARCIA
A la rencontre de Kafka, le log distribué par Florian GARCIAA la rencontre de Kafka, le log distribué par Florian GARCIA
A la rencontre de Kafka, le log distribué par Florian GARCIA
 
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
Voyage au centre du cerveau humain ou comment manipuler des données binaires ...
 
Ciel mon smartphone ! par Damien GOSSET
Ciel mon smartphone ! par Damien GOSSETCiel mon smartphone ! par Damien GOSSET
Ciel mon smartphone ! par Damien GOSSET
 

Kürzlich hochgeladen

Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSkajalroy875762
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon investment
 
Mckinsey foundation level Handbook for Viewing
Mckinsey foundation level Handbook for ViewingMckinsey foundation level Handbook for Viewing
Mckinsey foundation level Handbook for ViewingNauman Safdar
 
Cannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 UpdatedCannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 UpdatedCannaBusinessPlans
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxCynthia Clay
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...ssuserf63bd7
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Adnet Communications
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSCROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSpanmisemningshen123
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165meghakumariji156
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon investment
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All TimeCall 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Timegargpaaro
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...pujan9679
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptxRoofing Contractor
 

Kürzlich hochgeladen (20)

Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Mckinsey foundation level Handbook for Viewing
Mckinsey foundation level Handbook for ViewingMckinsey foundation level Handbook for Viewing
Mckinsey foundation level Handbook for Viewing
 
Cannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 UpdatedCannabis Legalization World Map: 2024 Updated
Cannabis Legalization World Map: 2024 Updated
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptx
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NSCROSS CULTURAL NEGOTIATION BY PANMISEM NS
CROSS CULTURAL NEGOTIATION BY PANMISEM NS
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
WheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond InsightsWheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond Insights
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All TimeCall 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 

Web Components: It’s all rainbows and unicorns! Is it? par Sara HARKOUSSE

  • 1. Web Components It's all rainbows and unicorns! Is it? Sara HARKOUSSE BlendWebMix Lyon, 26, 27 October 2017 1
  • 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 #BlendWebMix #webcomponents 2
  • 3. Women in Tech Duchess France @duchessfr duchess-france.org Elles bougent (Girls on The Move) @ellesbougent ellesbougent.com #BlendWebMix #webcomponents @Sara_harkousse 3
  • 4. Web Components It's all rainbows and unicorns! Is it? 4
  • 5. "The web components revolution" "A Tectonic shift for web development" "Web components are a game changer" Web components' public image #BlendWebMix #webcomponents @Sara_harkousse 5
  • 6. Web components' public image #BlendWebMix #webcomponents @Sara_harkousse "The broken promise of Web Components" 6
  • 7. Motivation #BlendWebMix #webcomponents @Sara_harkousse Modular architecture Filterable Product Table Search Bar Product Table Product Row Product Category Row 7
  • 8. 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 #BlendWebMix #webcomponents @Sara_harkousse Ember 2.16.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/ 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 8
  • 10. #BlendWebMix #webcomponents @Sara_harkousse Harmony happens when there is less learning curve 10
  • 11. Browser support use webcomponents.js #BlendWebMix #webcomponents @Sara_harkousse 11
  • 12. Refresher on web components Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web apps.” #BlendWebMix #webcomponents @Sara_harkousse 12
  • 13. Refresher on web components #BlendWebMix #webcomponents @Sara_harkousse HTML Template Tag HTML Imports Custom Elements Shadow DOM 13
  • 14. HTML Template Tag #BlendWebMix #webcomponents @Sara_harkousse <template id="template"> <div id="container"> <img class="webcomponents" src="logo.svg"> </div> </template> 14
  • 15. HTML Template Tag Usage #BlendWebMix #webcomponents @Sara_harkousse var template = document.querySelector('#template'); var clone = template.content.cloneNode(true); var host = document.querySelector('#host'); host.appendChild(clone); 15
  • 16. HTML Template Tag #BlendWebMix #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 16
  • 17. HTML Imports #BlendWebMix #webcomponents @Sara_harkousse <link rel="import" href="component.html"> <link rel="stylesheet" href="style.css"> <div id="container"> <img class="rotate" src="logo.svg"> </div> <script src="script.js"></script> 17
  • 18. How to get my component? #BlendWebMix #webcomponents @Sara_harkousse var link = document.querySelector('link[rel="import"]'); var content = link.import; // Grab DOM from component.html's document. var el = content.querySelector('#container'); var clone = el.cloneNode(true); var host = document.querySelector('#host'); host.appendChild(clone); 18
  • 19. #BlendWebMix #webcomponents @Sara_harkousse HTML Import requires a polyfill ES module? 19
  • 20. #BlendWebMix #webcomponents @Sara_harkousse ES module // export feature export const Component = // … // import feature import {Component} from '../components/cutom-component.js'; 20
  • 21. #BlendWebMix #webcomponents @Sara_harkousse Shadow DOM A tiny document exists inside of a host element 21
  • 22. #BlendWebMix #webcomponents @Sara_harkousse Key concepts Isolated DOM Scoped CSS 22
  • 23. #BlendWebMix #webcomponents @Sara_harkousse Shadow DOM requires a polyfill Hard to polyfill 23
  • 24. #BlendWebMix #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); } 24
  • 25. #BlendWebMix #webcomponents @Sara_harkousse Use/Don't use Shadow DOM? /* Use it */ :host { color: red; } /* Don't use it */ custom-component { color: red; } 25
  • 26. #BlendWebMix #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; } 26
  • 27. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements class CustomButton extends HTMLElement {...} window.customElements.define('custom-button', CustomButton); <custom-button></custom-button> Acts like a div 27
  • 28. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements class CustomButton extends HTMLButtonElement {...} window.customElements.define('custom-button', CustomButton, {extends: 'button'}); <button is="custom-button" disabled>My button!</button> Acts like a real button 28
  • 29. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements Namespace Dash (-) rule 29
  • 30. #BlendWebMix #webcomponents @Sara_harkousse Custom Elements ES6 Class class Custom-component extends HTMLElement { constructor() { super(); // always call super() first in the ctor. ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attrName, oldVal, newVal) { ... } } 30
  • 31. #BlendWebMix #webcomponents @Sara_harkousse Component example Bootstrap Progress Bar <div class="progress"> <div class="progress-bar" style="width: 60%;"> 60% </div> </div> 31
  • 32. window.customElements.define('progress-bar', ProgressBar); // Use <progress-bar></progress-bar> Component example https://jsfiddle.net/sara_harkousse/kwwe75yy/ 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); } static get observedAttributes() { return ['complete']; } 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 + '%'; } } connectedCallback() { var template = `<div class="progress-bar"> <div class="progress-bar-inner">${this.complete}%</div> </div>`; this.shadow.innerHTML = template; } } #BlendWebMix #webcomponents @Sara_harkousse 32
  • 33. #BlendWebMix #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-input attr="val"></custom-input> <progress-bar></progress-bar> </custom-pagecontent> <script> document.querySelector('custom-input').dispatchEvent(new CustomEvent('customevent', { detail: { prop: true } })); document.querySelector('progress-bar').addEventListener( 'customevent', function () { // do something } }); </script> </body> </html> 33
  • 34. #BlendWebMix #webcomponents @Sara_harkousse Takeaway Template tag? yeah! why not? Use ES module instead of HTML Imports Use Shadom DOM with a flag Custom Elements?? Go, Go, Go 34
  • 35. #BlendWebMix #webcomponents @Sara_harkousse Takeaway You will understand some of the design decisions of major frameworks if you learn about custom elements 35
  • 36. #BlendWebMix #webcomponents Thanks for listening! Follow for slides @Sara_harkousse https://github.com/SaraHarkousse 36