SlideShare a Scribd company logo
Mike North
CTO Levanto Financial
The Road to Native Web Components
INTRODUCTION
WHO’S THIS GUY?
▸ CTO Levanto Financial
▸ frontendmasters.com instructor
▸ Product Guy
▸ I do a lot of JavaScript OSS stuff
▸ I work with Ember & React a lot
DOCUMENT VIEWER
DOCUMENT
INTRO
DO YOU USE WEB COMPONENTS? (YES)
Michael North "The Road to Native Web Components"
Michael North "The Road to Native Web Components"
INTRO
THE W3C WEB COMPONENT SPEC
HTML IMPORTS
HTML TEMPLATES
CUSTOM ELEMENTS
SHADOW DOM
INTRO
THE W3C WEB COMPONENT SPEC
HTML IMPORTS
▸ require() for HTML
▸ onload, onerror events
▸ can bring in css/html/js
▸ closure-like js characteristics
INTRO
THE W3C WEB COMPONENT SPEC
CUSTOM ELEMENTS
▸ Custom HTML vocab
▸ Life-cycle
▸ Extensibility
▸ Interoperability (we hope?)
INTRO
THE W3C WEB COMPONENT SPEC
HTML TEMPLATES
▸ Inert HTML in the DOM
▸ Defer loading / rendering
▸ Think: handlebars/jade/etc…
INTRO
THE W3C WEB COMPONENT SPEC
SHADOW DOM
▸ CSS Encapsulation
▸ DOM encapsulation
▸ Each component has own
subtree w/in parent page
INTRO
THE W3C WEB COMPONENT SPEC
HTML IMPORTS
HTML TEMPLATES
CUSTOM ELEMENTS
SHADOW DOM
HTML TEMPLATES
<!DOCTYPE html>
<html>
<head></head>
<body>
<template id="something">
<div class="frame">
<h3 class="title">I am a title</h3>
<p class="body">I am the body</p>
</div>
</template>
</body>
</html>
<template id="something">
<div class="frame">
<h3 class="title">I am a title</h3>
<p class="body">I am the body</p>
</div>
</template>
<template id="something">
<!-- Some style -->
<style type="text/css">
.title {
font-size: 24px;
}
</style>
<!-- Some behavior -->
<script type="text/javascript">
</script>
<!-- Some structure and content -->
<div class="frame">
<h3 class="title">I am a title</h3>
<p class="body">I am the body</p>
</div>
</template>
// Grab the template
var tmpl = document.querySelector(‘#something');
Add the cloned document fragment to the DOM
document.body.appendChild(
// Clone the template's document fragment
document.importNode(tmpl.content, true)
);
// Grab the template
var tmpl = document.querySelector(‘#something');
Add the cloned document fragment to the DOM
document.body.appendChild(
// Clone the template's document fragment
document.importNode(tmpl.content, true)
);
http://codepen.io/TrueNorth/pen/xbyVgL?editors=101
HOW DO FRAMEWORKS
HANDLE THIS?
define('examples/templates/index', ['exports'], function (exports) {
'use strict';
exports['default'] = Ember.HTMLBars.template((function() {
return {
...
buildFragment: function buildFragment(dom) {
var el0 = dom.createDocumentFragment();
var el1 = dom.createTextNode("Hello, ");
dom.appendChild(el0, el1);
var el1 = dom.createElement("strong");
var el2 = dom.createComment("");
dom.appendChild(el1, el2);
var el2 = dom.createTextNode(" ");
dom.appendChild(el1, el2);
var el2 = dom.createComment("");
dom.appendChild(el1, el2);
dom.appendChild(el0, el1);
var el1 = dom.createTextNode("!");
dom.appendChild(el0, el1);
return el0;
},
buildRenderNodes: function buildRenderNodes(dom, fragment,
contextualElement) {
var element0 = dom.childAt(fragment, [1]);
var morphs = new Array(2);
morphs[0] = dom.createMorphAt(element0,0,0);
morphs[1] = dom.createMorphAt(element0,2,2);
return morphs;
},
statements: [
["content","firstName",["loc",[null,[1,15],[1,28]]]],
["content","lastName",["loc",[null,[1,29],[1,41]]]]
],
...
};
}()));
});
LAZY LOADING
Lazy engines, JIT template compiler
Webpack chunking
Webpack chunking
SHADOW DOM
APPLICATION DOM
COMPONENT
SHADOW DOM
SHADOW DOM
ENCAPSULATION http://codepen.io/mike-north/pen/OPBNmq?editors=101
SHADOW DOM
CSS ENCAPSULATION
▸ CSS rules do not usually pierce
shadow roots
▸ CSS defined inside the shadow
root only affects that DOM
▸ :host pseudo-selector for
component boundary
▸ ::shadow penetrates shadow
roots
▸ /deep/ is deprecated
// Inside shadow root
:host {
border: 1px solid red;
}
:host(.hover) {
border: 1px solid blue;
}
// Outside shadow root
#my-thing::shadow p {
color: green;
}
HOW DO FRAMEWORKS
HANDLE THIS?
CSS ENCAPSULATION
ember-css-modules
ember-component-css
“component styles”
react-css-modules
Michael North "The Road to Native Web Components"
SHADOW DOM
CONTENT PROJECTION
<textarea name="comment" id="" cols="30" >
This is the content of my textarea
</textarea>
SHADOW DOM
CONTENT PROJECTION
http://codepen.io/mike-north/pen/emPZMv?editors=1000
CONTENT PROJECTION
{{yield}}
2.x <ng-content>, 1.x ng-transclude
this.props.children
HTML IMPORTS
<link rel="import" href="myfile.html" />
<link rel="import" href="myfile.html" />
// Get document fragment of an import
var content = document
.querySelector('link[rel="import"]')
.import;
<link rel="import" href="myfile.html" />
// Get document fragment of an import
var content = document
.querySelector('link[rel="import"]')
.import;
// From a <script> included with the import,
// access imported DOM
var $abc = document
.currentScript
.ownerDocument
.querySelector('.abc');
HOW DO FRAMEWORKS
HANDLE THIS?
IMPORTING COMPONENTS
import MyComponent from 'my-component';
CUSTOM
ELEMENTS
CUSTOM ELEMENTS
WHY IS THIS IMPORTANT
▸ Composable building
blocks
▸ Life-cycle
▸ Extensibility
▸ Alignment of HTML with
mental model of your UI
CUSTOM ELEMENTS
REGISTERING
// Extend a DOM element prototype
var MegaButtonProto =
Object.create(HTMLButtonElement.prototype);
CUSTOM ELEMENTS
REGISTERING
// Extend a DOM element prototype
var MegaButtonProto =
Object.create(HTMLButtonElement.prototype);
// Register your new element type
var MegaButton =
document.registerElement("mega-button", {
prototype: MegaButtonProto,
extends: "button"
});
CUSTOM ELEMENTS
ADDING A TEMPLATE
// Template
var infoBoxTemplate = document.querySelector('#info-pane-template');
// Extend a DOM element
var InfoBoxProto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
// Create the shadow root
this.createShadowRoot().appendChild(
// Add the template to the shadow root
document.importNode(infoBoxTemplate.content, true)
);
}
}
});
CUSTOM ELEMENTS
ADDING A TEMPLATE
// Template
var infoBoxTemplate = document.querySelector('#info-pane-template');
// Extend a DOM element
var InfoBoxProto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
// Create the shadow root
this.createShadowRoot().appendChild(
// Add the template to the shadow root
document.importNode(infoBoxTemplate.content, true)
);
}
}
});
// Template
var infoBoxTemplate = document.querySelector('#info-pane-template');
// Extend a DOM element
var InfoBoxProto = Object.create(HTMLElement.prototype, {
createdCallback: {
value: function() {
// Create the shadow root
this.createShadowRoot().appendChild(
// Add the template to the shadow root
document.importNode(infoBoxTemplate.content, true)
);
}
}
});
CUSTOM ELEMENTS
ADDING A TEMPLATE
HOW DO FRAMEWORKS
HANDLE THIS?
CUSTOM ELEMENTS
Ember.Component
@Component
React.Component
DEMO
DEMO
•Starting Point: http://codepen.io/TrueNorth/pen/PwdLrj
•Componentized: http://codepen.io/TrueNorth/pen/xbyqME
•HTML Importified: http://codepen.io/TrueNorth/pen/ogawLm
THANKS!
michael.l.north@gmail.com @MICHAELLNORTH

More Related Content

PDF
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
PDF
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
PDF
Vuejs testing
PDF
Polyglot automation - QA Fest - 2015
PDF
Node.js and Selenium Webdriver, a journey from the Java side
PPTX
Testing frontends with nightwatch & saucelabs
PDF
Night Watch with QA
PDF
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Григорий Шехет "Treasure hunt in the land of Reactive frameworks"
Роман Лютиков "Web Apps Performance & JavaScript Compilers"
Vuejs testing
Polyglot automation - QA Fest - 2015
Node.js and Selenium Webdriver, a journey from the Java side
Testing frontends with nightwatch & saucelabs
Night Watch with QA
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...

What's hot (20)

PDF
Building scalable applications with angular js
PDF
Fullstack End-to-end test automation with Node.js, one year later
PDF
Design Patterns in XCUITest
PDF
Intro to JavaScript
PDF
Nightwatch at Tilt
PDF
Easy tests with Selenide and Easyb
ZIP
Automated Frontend Testing
PPTX
Code ceptioninstallation
PDF
Kiss PageObjects [01-2017]
PDF
Angular - Improve Runtime performance 2019
PDF
Ngrx meta reducers
PPTX
webworkers
PDF
Angular - injection tokens & Custom libraries
PDF
The Gist of React Native
PPTX
Protractor framework – how to make stable e2e tests for Angular applications
PDF
Exploring Angular 2 - Episode 2
PDF
Test Driven Development with JavaFX
PDF
XebiConFr 15 - Brace yourselves Angular 2 is coming
PDF
Type script for_java_dev_jul_2020
PDF
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Building scalable applications with angular js
Fullstack End-to-end test automation with Node.js, one year later
Design Patterns in XCUITest
Intro to JavaScript
Nightwatch at Tilt
Easy tests with Selenide and Easyb
Automated Frontend Testing
Code ceptioninstallation
Kiss PageObjects [01-2017]
Angular - Improve Runtime performance 2019
Ngrx meta reducers
webworkers
Angular - injection tokens & Custom libraries
The Gist of React Native
Protractor framework – how to make stable e2e tests for Angular applications
Exploring Angular 2 - Episode 2
Test Driven Development with JavaFX
XebiConFr 15 - Brace yourselves Angular 2 is coming
Type script for_java_dev_jul_2020
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
Ad

Viewers also liked (20)

PDF
4 puchnina.pptx
PPTX
"Красная книга веб-разработчика" Виктор Полищук
PPTX
Швейцарія, масштабування Scrum і розподілені команди от Романа Сахарова
PDF
Евгений Жарков AngularJS: Good parts
PDF
Павел Тайкало: "Optimistic Approach : How to show results instead spinners wi...
PDF
Андрей Шумада | Tank.ly
PDF
Lightweight APIs in mRuby (Михаил Бортник)
PDF
Алексей Рыбаков: "Wearable OS год спустя: Apple Watch 2.0, Android Wear 5.1.1...
PDF
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
PPTX
Трансформация команды: от инди разработки к играм с коммерческой успешностью
PDF
Анатолий Попель: "Формы оплаты и платёжные шлюзы"
PDF
"Frameworks in 2015" Андрей Листочкин
PDF
Илья Прукко: "Как дизайнеру не становиться художником"
PPT
"Spring Boot. Boot up your development" Сергей Моренец
PDF
Александр Воронов | Building CLI with Swift
PDF
"После OOD: как моделировать предметную область в пост-объектном мире" Руслан...
PDF
Fighting Fat Models (Богдан Гусев)
PPTX
Сергей Жук "Android Performance Tips & Tricks"
PDF
Евгений Обрезков "Behind the terminal"
PDF
Алексей Волков "Интерактивные декларативные графики на React+D3"
4 puchnina.pptx
"Красная книга веб-разработчика" Виктор Полищук
Швейцарія, масштабування Scrum і розподілені команди от Романа Сахарова
Евгений Жарков AngularJS: Good parts
Павел Тайкало: "Optimistic Approach : How to show results instead spinners wi...
Андрей Шумада | Tank.ly
Lightweight APIs in mRuby (Михаил Бортник)
Алексей Рыбаков: "Wearable OS год спустя: Apple Watch 2.0, Android Wear 5.1.1...
Александр Махомет "Feature Flags. Уменьшаем риски при выпуске изменений"
Трансформация команды: от инди разработки к играм с коммерческой успешностью
Анатолий Попель: "Формы оплаты и платёжные шлюзы"
"Frameworks in 2015" Андрей Листочкин
Илья Прукко: "Как дизайнеру не становиться художником"
"Spring Boot. Boot up your development" Сергей Моренец
Александр Воронов | Building CLI with Swift
"После OOD: как моделировать предметную область в пост-объектном мире" Руслан...
Fighting Fat Models (Богдан Гусев)
Сергей Жук "Android Performance Tips & Tricks"
Евгений Обрезков "Behind the terminal"
Алексей Волков "Интерактивные декларативные графики на React+D3"
Ad

Similar to Michael North "The Road to Native Web Components" (20)

PDF
Modern Web UI - Web components
PDF
Web Component
PPTX
Web Components Revolution
PDF
The Time for Vanilla Web Components has Arrived
PPTX
Web components
PPTX
Web Components: Introduction and Practical Use Cases
PPTX
Web components. Compose the web.
PDF
Web component driven development
PPTX
Polymer and web component
PDF
Introduction to Web Components
PDF
Brownbag on basics of web components
PPTX
Magic of web components
PPTX
Rawnet Lightning Talk - Web Components
PDF
2014 03-25 - GDG Nantes - Web Components avec Polymer
PDF
Real World Web components
PDF
Web components
PDF
Polymer - pleasant client-side programming with web components
PDF
Devoxx 2014-webComponents
PDF
Introduction to web components
PDF
Web components the future is here
Modern Web UI - Web components
Web Component
Web Components Revolution
The Time for Vanilla Web Components has Arrived
Web components
Web Components: Introduction and Practical Use Cases
Web components. Compose the web.
Web component driven development
Polymer and web component
Introduction to Web Components
Brownbag on basics of web components
Magic of web components
Rawnet Lightning Talk - Web Components
2014 03-25 - GDG Nantes - Web Components avec Polymer
Real World Web components
Web components
Polymer - pleasant client-side programming with web components
Devoxx 2014-webComponents
Introduction to web components
Web components the future is here

More from Fwdays (20)

PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
PPTX
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
PPTX
"Як ми переписали Сільпо на Angular", Євген Русаков
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
PDF
"Validation and Observability of AI Agents", Oleksandr Denisyuk
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
PPTX
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
PPTX
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
PDF
"AI is already here. What will happen to your team (and your role) tomorrow?"...
PPTX
"Is it worth investing in AI in 2025?", Alexander Sharko
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
PDF
"Database isolation: how we deal with hundreds of direct connections to the d...
PDF
"Scaling in space and time with Temporal", Andriy Lupa .pdf
PPTX
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
PPTX
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
PPTX
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
"Effect, Fiber & Schema: tactical and technical characteristics of Effect.ts"...
"Computer Use Agents: From SFT to Classic RL", Maksym Shamrai
"Як ми переписали Сільпо на Angular", Євген Русаков
"AI Transformation: Directions and Challenges", Pavlo Shaternik
"Validation and Observability of AI Agents", Oleksandr Denisyuk
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
"Co-Authoring with a Machine: What I Learned from Writing a Book on Generativ...
"Human-AI Collaboration Models for Better Decisions, Faster Workflows, and Cr...
"AI is already here. What will happen to your team (and your role) tomorrow?"...
"Is it worth investing in AI in 2025?", Alexander Sharko
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Database isolation: how we deal with hundreds of direct connections to the d...
"Scaling in space and time with Temporal", Andriy Lupa .pdf
"Provisioning via DOT-Chain: from catering to drone marketplaces", Volodymyr ...
" Observability with Elasticsearch: Best Practices for High-Load Platform", A...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"Istio Ambient Mesh in production: our way from Sidecar to Sidecar-less",Hlib...

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Understanding_Digital_Forensics_Presentation.pptx
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...

Michael North "The Road to Native Web Components"