Web Components
-
Natif -
StencilJS -
LitElement
devoxxfr-hol
/ hola#4321
Puis dans les répertoires native
, stencil
, lit-element
, faire
$ npm ci
http://bit.ly/dvx-wc-slides I think I've had milk last longer than some JavaScript frameworks.
— I Am Devloper (@iamdevloper) December 4, 2014
😨 Stencil et litElement sont 5 fois plus petits qu'Angular
😱 Native est 23 fois plus petit qu'Angular
😨 Angular est 3 fois plus lent
Spécifier par le World Wide Web Consortium (W3C)
Débuté en 2012
Les Custom Elements sont la capacité de créer un balise HTML avec ses propres attributs et méthodes
Le Shadow DOM fournit l'encapsulation du DOM et du CSS
Définit un bloc d'HTML réutilisable au moment de l'exécution
class PopUpInfo extends HTMLElement {
constructor() {
super();
// ...
}
// ...
}
customElements.define('popup-info', PopUpInfo);
Custom Elements (V1) | 😫 | 😫 | 😃 | 😃 | 🙂 |
---|---|---|---|---|---|
Shadow DOM (V1) | 😫 | 😫 | 😃 | 😃 | 🙂 |
HTML templates | 😫 | 😃 | 😃 | 😃 | 😃 |
Custom Elements (V1) | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
---|---|---|---|---|---|
Shadow DOM (V1) | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
HTML templates | ✔︎ | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
Projet Open Source, MIT License
Créé par l'équipe d'Ionic en 2017
5.2k ⭐️ sur github
JSX / Virtual DOM | ✘ | ✘ | ✔︎ | ✔︎ |
---|---|---|---|---|
TypeScript | ✘ | ✔︎ | ✘ | ✔︎ |
Decorators | ✘ | ✔︎ | ✘ | ✔︎ |
Prerendering SSR | ✘ | ✘ | ✘ | ✔︎ |
Il charge les polyfills à la demande
import {Component, Prop} from '@stencil/core';
@Component({
tag: 'my-first-component',
styleUrl: 'my-first-component.scss'
})
export class MyComponent {
// Indicate that name should be
// a public property on the component
@Prop() name: string;
render() {
// JSX
return (<p>My name is {this.name}</p>);
}
}
$ npm init stencil
? Pick a starter › - Use arrow-keys. Return to submit.
❯ ionic-pwa Everything you need to build fast, production ready PWAs
app Minimal starter for building a Stencil app or website
component Collection of web components that can be used anywhere
Projet Open Source, BSD 3-Clause License
Créer par l'équipe Polymer Team en 2017
2.0k ⭐️ sur github
4.4k ⭐️ sur github
Basé sur les templates HTML
Avec les Template literals de ES2015
import {html, render} from 'lit-html';
// A lit-html template uses
// the `html` template tag:
const sayHello = (name) =>
html`<h1>Hello ${name}</h1>`;
// It's rendered with the `render()` function:
render(sayHello('World'), document.body);
// And re-renders only update the
// data that changed, without VDOM diffing!
render(sayHello('Everyone'), document.body);
import { LitElement, html, css } from 'https://unpkg.com/lit-element/lit-element.js?module';
class MyElement extends LitElement {
static get properties() {
return {
mood: { type: String }
}
}
static get styles() {
return css`.mood { color: green; }`;
}
render() {
return html`Web Components are
<span class="mood">${this.mood}</span>!`;
}
}
customElements.define('my-element', MyElement);
import { /* ... */ } from 'lit-element';
@customElement('my-element')
class MyElement extends LitElement {
@property({ type: String }) mood;
static get styles() {
return css`.mood { color: green; }`;
}
render() {
return html`Web Components are
<span class="mood">${this.mood}</span>!`;
}
}
✅ Chrome, Safari, Opera, Firefox
polyfills pour Edge et IE 11
Support des navigateurs
Ne remplacera pas vos frameworks
Accessibilité
Theming
Form validation / submission / autofill
SSR pour lit-html et litElement
...
Pensez à nous faire des retours (votez !)