SlideShare a Scribd company logo
COMPONENTIZE YOUR
WEB APPS WITH WEB
COMPONENTS
Gil Fink
CEO and Senior Consultant, sparXys
@gilfink
We all love <div> soup
We all love <div> soup
3
Known website markup…
What if…
There’s an <element> for
that
About Me
• sparXys CEO and senior consultant
• Microsoft MVP in the last 8 years
• Pro Single Page Application Development (Apress)
co-author
• 4 Microsoft Official Courses (MOCs) co-author
• GDG Rishon and AngularUP co-organizer
Agenda
• Components?
• HTML5 Web Components
o Templates
o Imports
o Shadow DOM
o Custom Elements
Component Definition
• A component is
o Independent software unit
o Can be composed with other components
Component
Characteristics
• Independent
o A component should be independent
• Composable
o All external interactions must take place through publicly defined
interfaces (API)
• Deployable
o Self-contained and must be able to operate as a stand-alone entity
Typical Web Page
Breaking The Page into
Components
Header + Toolbar
About
Main Section
What’s
new
Schedule
Summary
Recent list
From Design to
Implementation
Main Section
Schedule
Summary
Recent list
Component
Child Component
Child Component
Child Component
<main-section>
<schedule>
<summary>
<recent-list>
Components Tree
<main-section>
<schedule> <summary> <recent-list>
<main-section>
<schedule>
<summary>
<recent-list>
Component Types
• Stateless
• Stateful
• Routed
Stateless Components
• Define inputs/outputs
• Data enters via a property (input)
• Data leaves via events (output)
• Stateless/dumb/presentational
<schedule>
<summary>
<recent-list>
Stateful Components
• Communicate with services and states
• Don’t directly mutate states
• Render child components
• Stateful/smart/container
<main-section>
Routed Components
• Same as stateful component
• Includes a route definition bound to the component
<Route>
<about> <main-section> <whats-new>
HTML5 Web Components
HTML5 Web Components
• A set of standards designed to componentize the
web
• Some general goals:
Code Reuse Encapsulation
Separation of
Concerns
Composition Theming Expressive Semantic
The Web Components
Standards
•Reusable DOM fragmentsTemplates
•Load HTML declarativelyImports
•DOM encapsulationShadow DOM
•Create your own elements
Custom
Elements
Setting The Environment
• Browsers have only partial support for Web
Components
o We should use the webcomponents.js Polyfill
o Download: https://github.com/webcomponents/webcomponentsjs/
• Install using your favorite package manager
(npm/Bower/Nuget)
• Make sure the Polyfill script runs first!
Let’s drill down
Templates
• A new HTML element – template
• Can be used to instantiate document fragments
• Can wrap HTML, style tags and script tags
• No data binding support
<template id=”myTemplate”>
<div>
…
</div>
</template>
Cloning a Template
• Select the template and extract its content
o Use the importNode function to get the cloned content
• Only when the clone is appended to the DOM
o The style and JavaScript are executed
o Resources like images are retrieved from the server
var template = document.querySelector(‘#myTemplate’);
var clone = document.importNode(template.content, true);
Templates
Demo
Imports
• Load additional HTML documents
o Without using Ajax
• A new type of link tag
• Use the rel attribute with the import type:
<link rel=”import” href=”myImport.html”>
Imports and Bundling
• Enable to bundle a full component into one HTML
file
o The HTML can include scripts and CSS styles
• The whole bundle can be retrieved in a single call
Imports and The DOM
• Importing a document doesn’t include it into the
DOM
o It will parse it in memory and load all the additional resources
• Use the import property of the link tag:
var content = document.querySelector(‘link[rel=”import”]’).import;
Imports
Demo
Import Additional Notes
• Scripts running inside the import can reference the
containing document by calling
document.currentScript.ownerDocument
• CORS constraints apply to documents imported
from other domains
Shadow DOM
• Encapsulate DOM parts
o The browser will know how to present those parts
o The browser won’t show the encapsulated parts in the source code
• Creates a boundary between the component and
its user
The Problems Shadow
DOM Tries to Solve
• Encapsulation of components/widgets
• Style leakage
o Leaks from one component to another
o Leaks from imported 3th party library/framework
• Global DOM
o id or class attributes all over the place
Shadow DOM in The
Browser
<video src="media/myVideo.mp4" controls></video>
<input type="date">
Shadow DOM – Cont.
• Use the createShadowRoot function to wrap an
element as a shadow DOM:
var host = document.querySelector(‘#shadowDOMHost’);
var root = host.createShadowRoot();
root.innerHTML = ‘<div>Lurking in the shadows</div>’;
Styling Shadow DOM
• :host and :host() pseudo-class
• ::content pseudo-element
<div name="myElement">
<style>
:host {
border: 1px solid lightgray;
}
</style>
<template>...</template>
</div>
Shadow DOM
Demo
Custom Elements
• Enable to extend or to create custom HTML
elements
o The new element must inherit from HTMLElement
• Create a custom element using the registerElement
function:
• Extend an existing element:
var myElement = document.registerElement(‘my-element’);
var myInput = document.registerElement(‘my-input’, {
prototype: Object.create(HTMLInputElement.prototype),
extends: ‘input’
});
Custom Elements –
Naming
• You can create named elements (almost) any way
you want:
o Same naming rules as other HTML tags
o There must be a dash (“-”) in the name
• To future-proof the name against the HTML standard
• To avoid naming collisions
Custom Elements – Usage
• Use the element in your DOM:
or use the createElement function:
<my-input></my-input>
var elm = document.createElement(‘my-input’);
Custom Element
Callbacks
• Custom elements have life cycle events:
• createdCallback
o Called when an instance is created
• attachedCallback
o Called when an instance is added to DOM subtree
• detachedCallback
o Called when an instance is removed from a DOM subtree
• attributeChangedCallback
o Called after an attribute value changes
Custom Elements
Demo
The Current State of Web
Components
• Still W3C Working Drafts
• Browser support:
http://caniuse.com/#search=web%20components
• Main libraries:
Polymer X-Tag
Summary
• Web Components are emerging standards that
enables:
• Encapsulation
• Separation of Concerns
• Element portability
• And more
• Taking the web one step forward!
Resources
• http://webcomponents.org/
• My Blog – http://www.gilfink.net
• Follow me on Twitter – @gilfink
Thank You!

More Related Content

What's hot

How to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS projectHow to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS project
Renoir Boulanger
 

What's hot (20)

Css floats
Css floatsCss floats
Css floats
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Intro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS PropertyIntro to Flexbox - A Magical CSS Property
Intro to Flexbox - A Magical CSS Property
 
Web development
Web developmentWeb development
Web development
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
Web Components
Web ComponentsWeb Components
Web Components
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
Html & Css presentation
Html  & Css presentation Html  & Css presentation
Html & Css presentation
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
BEM it! Introduction to BEM methodology
BEM it! Introduction to BEM methodologyBEM it! Introduction to BEM methodology
BEM it! Introduction to BEM methodology
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
How to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS projectHow to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS project
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
 

Similar to Web components

Similar to Web components (20)

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
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
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
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Web components
Web componentsWeb components
Web components
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
 
BreizhBeans - Web components
BreizhBeans - Web componentsBreizhBeans - Web components
BreizhBeans - Web components
 
Web Components
Web ComponentsWeb Components
Web Components
 
Dom
DomDom
Dom
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is here
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Polymer
PolymerPolymer
Polymer
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is Here
 
Web components
Web componentsWeb components
Web components
 

More from Gil Fink

More from Gil Fink (20)

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech Speaker
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speaker
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service Workers
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type script
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databases
 
Biological modeling, powered by angular js
Biological modeling, powered by angular jsBiological modeling, powered by angular js
Biological modeling, powered by angular js
 
Whos afraid of front end databases?
Whos afraid of front end databases?Whos afraid of front end databases?
Whos afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with StrimziStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
How To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdfHow To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 

Web components

  • 1. COMPONENTIZE YOUR WEB APPS WITH WEB COMPONENTS Gil Fink CEO and Senior Consultant, sparXys @gilfink
  • 2. We all love <div> soup
  • 3. We all love <div> soup 3 Known website markup…
  • 6. About Me • sparXys CEO and senior consultant • Microsoft MVP in the last 8 years • Pro Single Page Application Development (Apress) co-author • 4 Microsoft Official Courses (MOCs) co-author • GDG Rishon and AngularUP co-organizer
  • 7. Agenda • Components? • HTML5 Web Components o Templates o Imports o Shadow DOM o Custom Elements
  • 8. Component Definition • A component is o Independent software unit o Can be composed with other components
  • 9. Component Characteristics • Independent o A component should be independent • Composable o All external interactions must take place through publicly defined interfaces (API) • Deployable o Self-contained and must be able to operate as a stand-alone entity
  • 11. Breaking The Page into Components Header + Toolbar About Main Section What’s new Schedule Summary Recent list
  • 12. From Design to Implementation Main Section Schedule Summary Recent list Component Child Component Child Component Child Component <main-section> <schedule> <summary> <recent-list>
  • 13. Components Tree <main-section> <schedule> <summary> <recent-list> <main-section> <schedule> <summary> <recent-list>
  • 14. Component Types • Stateless • Stateful • Routed
  • 15. Stateless Components • Define inputs/outputs • Data enters via a property (input) • Data leaves via events (output) • Stateless/dumb/presentational <schedule> <summary> <recent-list>
  • 16. Stateful Components • Communicate with services and states • Don’t directly mutate states • Render child components • Stateful/smart/container <main-section>
  • 17. Routed Components • Same as stateful component • Includes a route definition bound to the component <Route> <about> <main-section> <whats-new>
  • 19. HTML5 Web Components • A set of standards designed to componentize the web • Some general goals: Code Reuse Encapsulation Separation of Concerns Composition Theming Expressive Semantic
  • 20. The Web Components Standards •Reusable DOM fragmentsTemplates •Load HTML declarativelyImports •DOM encapsulationShadow DOM •Create your own elements Custom Elements
  • 21. Setting The Environment • Browsers have only partial support for Web Components o We should use the webcomponents.js Polyfill o Download: https://github.com/webcomponents/webcomponentsjs/ • Install using your favorite package manager (npm/Bower/Nuget) • Make sure the Polyfill script runs first!
  • 23. Templates • A new HTML element – template • Can be used to instantiate document fragments • Can wrap HTML, style tags and script tags • No data binding support <template id=”myTemplate”> <div> … </div> </template>
  • 24. Cloning a Template • Select the template and extract its content o Use the importNode function to get the cloned content • Only when the clone is appended to the DOM o The style and JavaScript are executed o Resources like images are retrieved from the server var template = document.querySelector(‘#myTemplate’); var clone = document.importNode(template.content, true);
  • 26. Imports • Load additional HTML documents o Without using Ajax • A new type of link tag • Use the rel attribute with the import type: <link rel=”import” href=”myImport.html”>
  • 27. Imports and Bundling • Enable to bundle a full component into one HTML file o The HTML can include scripts and CSS styles • The whole bundle can be retrieved in a single call
  • 28. Imports and The DOM • Importing a document doesn’t include it into the DOM o It will parse it in memory and load all the additional resources • Use the import property of the link tag: var content = document.querySelector(‘link[rel=”import”]’).import;
  • 30. Import Additional Notes • Scripts running inside the import can reference the containing document by calling document.currentScript.ownerDocument • CORS constraints apply to documents imported from other domains
  • 31. Shadow DOM • Encapsulate DOM parts o The browser will know how to present those parts o The browser won’t show the encapsulated parts in the source code • Creates a boundary between the component and its user
  • 32. The Problems Shadow DOM Tries to Solve • Encapsulation of components/widgets • Style leakage o Leaks from one component to another o Leaks from imported 3th party library/framework • Global DOM o id or class attributes all over the place
  • 33. Shadow DOM in The Browser <video src="media/myVideo.mp4" controls></video> <input type="date">
  • 34. Shadow DOM – Cont. • Use the createShadowRoot function to wrap an element as a shadow DOM: var host = document.querySelector(‘#shadowDOMHost’); var root = host.createShadowRoot(); root.innerHTML = ‘<div>Lurking in the shadows</div>’;
  • 35. Styling Shadow DOM • :host and :host() pseudo-class • ::content pseudo-element <div name="myElement"> <style> :host { border: 1px solid lightgray; } </style> <template>...</template> </div>
  • 37. Custom Elements • Enable to extend or to create custom HTML elements o The new element must inherit from HTMLElement • Create a custom element using the registerElement function: • Extend an existing element: var myElement = document.registerElement(‘my-element’); var myInput = document.registerElement(‘my-input’, { prototype: Object.create(HTMLInputElement.prototype), extends: ‘input’ });
  • 38. Custom Elements – Naming • You can create named elements (almost) any way you want: o Same naming rules as other HTML tags o There must be a dash (“-”) in the name • To future-proof the name against the HTML standard • To avoid naming collisions
  • 39. Custom Elements – Usage • Use the element in your DOM: or use the createElement function: <my-input></my-input> var elm = document.createElement(‘my-input’);
  • 40. Custom Element Callbacks • Custom elements have life cycle events: • createdCallback o Called when an instance is created • attachedCallback o Called when an instance is added to DOM subtree • detachedCallback o Called when an instance is removed from a DOM subtree • attributeChangedCallback o Called after an attribute value changes
  • 42. The Current State of Web Components • Still W3C Working Drafts • Browser support: http://caniuse.com/#search=web%20components • Main libraries: Polymer X-Tag
  • 43. Summary • Web Components are emerging standards that enables: • Encapsulation • Separation of Concerns • Element portability • And more • Taking the web one step forward!
  • 44. Resources • http://webcomponents.org/ • My Blog – http://www.gilfink.net • Follow me on Twitter – @gilfink