SlideShare a Scribd company logo
1 of 46
Download to read offline
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Web Components - The Future is
Here
Gil Fink
CEO and Senior Consultant, sparXys
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
The Pyramid of Doom
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
About Me
• sparXys CEO and Senior consultant
• ASP.NET/IIS Microsoft MVP
• Co-author of Pro Single Page Application
Development (Apress)
• Co-author of 4 Microsoft Official Courses (MOCs)
Agenda
• The problems we face
• Web Components APIs
o Templates
o Imports
o Shadow DOM
o Custom Elements
• Libraries to the rescue
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
1. Undescriptive Markup
Markup Example
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
2. Poor Separation of
Concerns
You want HTML, CSS and
JavaScript to work together
You end up with a mess
The wiring gets in your way!
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
3. No Native Templates
• Store HTML in hidden DOM element and show it
• Use script tag as a template holder:
<script id=”myTemplate” type=”text/template”>
<div>
…
</div>
</script>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
4. No Bundling
• You want to bundle a complex component
The component includes HTML, CSS and JavaScript
how would you do that?
o Use a server side wrapping mechanism?
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Web Components to the
Rescue
• A set of standards designed to componentize the
web
• Some general goals:
Code Reuse Encapsulation
Separation of
Concerns
Composition Theming Expressive Semantic
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
The Web Components
Standards
•Reusable DOM fragmentsTemplates
•Load HTML declarativelyImports
•DOM encapsulationShadow DOM
•Create your own elements
Custom
Elements
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Setting The Environment
• Browsers have only partial support for Web
Components
o So we use the webcomponents.js Polyfill for Web Components
• Download:
o https://github.com/webcomponents/webcomponentsjs/
o Or install using your favorite package manager (Bower, Nuget)
• Make sure the Polyfill script runs first
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Demo
Setting the environment
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Let’s Drill Down
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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 
• To use the template you need some JavaScript
magic
<template id=”myTemplate”>
<div>
…
</div>
</template>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Cloning a Template
• Select the template and extract its content
o Using its content property
• 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);
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Templates
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Imports
• Load additional HTML documents
o Without Ajax
• A new type of link tag
• Use the rel attribute with the import type:
<link rel=”import” href=”myImport.html”>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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;
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Imports
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Shadow DOM in The
Browser
<video src="media/myVideo.mp4" controls></video>
<input type="date">
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Show Shadow DOM
Elements in Chrome
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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>’;
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Styling Shadow DOM
• :host and :host() pseudo-class
• ::content pseudo-element
<div name="myElement">
<style>
:host {
border: 1px solid lightgray;
}
</style>
<template>...</template>
</div>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Shadow DOM
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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’
});
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Custom Elements – Usage
• Use the element in your DOM:
or use the createElement function:
<my-input></my-input>
var elm = document.createElement(‘my-input’);
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
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
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Custom Elements
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
The Current State of Web
Components
• Still W3C Working Drafts
• Browser support:
http://caniuse.com/#search=web%20components
• Main libraries:
Polymer X-Tag
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Polymer
• Components library that is written and maintained
by Google
• Includes
o Ability to build your own custom components
o Ready to use web components
• Polymer leverages the web components standard
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Polymer Catalog
• Full catalog that includes various ready to use
components
• You can look at the component categories here:
https://elements.polymer-project.org/
• Support to Google material design and Google API
components included
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Creating Custom
Elements in Polymer
<dom-module id="contact-card">
<link rel="import" type="css" href="contact-card.css">
<template>
<content></content>
<iron-icon icon="star" hidden$="{{!starred}}"></iron-icon>
</template>
<script>
Polymer({
is: 'contact-card',
properties: {
starred: Boolean
}
});
</script>
</dom-module>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Using The Custom
Elements in Polymer
<contact-card starred>
<img src="profile.jpg" alt="Gil's photo">
<span>Gil Fink</span>
</contact-card>
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Polymer
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
X-Tag
• Components library that is supported by Microsoft
• Includes only the ability to write your own custom
components
o Ready to use web components can be found in the Brick library
• X-Tag leverages the web components standard
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Creating Web
Components in X-Tag
xtag.register('x-myelement', {
lifecycle: {
created: function(){
// do something when the element is created
}
},
events: {
focus: function(){
// do something when the element in focus
}
},
methods: {
someMethod: function(){
// implementation
} }
});
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
X-Tag
Demo
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Questions?
Summary
• Web Components are emerging standards that
enables:
• Encapsulation
• Separation of Concerns
• Element portability
• And more
• They are still in development
• Taking the web one step forward!
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Resources
• Download the slide deck:
http://bit.ly/1OCOnbL
• http://webcomponents.org/
https://www.polymer-project.org/1.0/
http://www.x-tags.org/
• My Blog – http://www.gilfink.net
• Follow me on Twitter – @gilfink
Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
Thank You!

More Related Content

What's hot

Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkImam Raza
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSSAndrew Rota
 
The Future of the Web: HTML5
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5Derek Bender
 
The Truth About Your Web App's Performance
The Truth About Your Web App's PerformanceThe Truth About Your Web App's Performance
The Truth About Your Web App's PerformanceJohn Riviello
 
Razor into the Razor'verse
Razor into the Razor'verseRazor into the Razor'verse
Razor into the Razor'verseEd Charbeneau
 
Polymer / WebComponents
Polymer / WebComponentsPolymer / WebComponents
Polymer / WebComponentsArnaud Kervern
 
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Spyros Ioakeimidis
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCMayflower GmbH
 
Polymer presentation in Google HQ
Polymer presentation in Google HQPolymer presentation in Google HQ
Polymer presentation in Google HQHarshit Pandey
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & FriendsRemy Sharp
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Gil Fink
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is HereGil Fink
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeLaurence Svekis ✔
 
HTML5 - Introduction
HTML5 - IntroductionHTML5 - Introduction
HTML5 - IntroductionDavy De Pauw
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsLaurence Svekis ✔
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptKaty Slemon
 
JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1Gene Babon
 

What's hot (20)

Google Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talkGoogle Developer Group(GDG) DevFest Event 2012 Android talk
Google Developer Group(GDG) DevFest Event 2012 Android talk
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Top java script frameworks ppt
Top java script frameworks pptTop java script frameworks ppt
Top java script frameworks ppt
 
The Future of the Web: HTML5
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5
 
The Truth About Your Web App's Performance
The Truth About Your Web App's PerformanceThe Truth About Your Web App's Performance
The Truth About Your Web App's Performance
 
Razor into the Razor'verse
Razor into the Razor'verseRazor into the Razor'verse
Razor into the Razor'verse
 
Polymer / WebComponents
Polymer / WebComponentsPolymer / WebComponents
Polymer / WebComponents
 
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
 
HTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPCHTML5 for PHP Developers - IPC
HTML5 for PHP Developers - IPC
 
Polymer presentation in Google HQ
Polymer presentation in Google HQPolymer presentation in Google HQ
Polymer presentation in Google HQ
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is Here
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
HTML5 - Introduction
HTML5 - IntroductionHTML5 - Introduction
HTML5 - Introduction
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
 
Getting started with angular js
Getting started with angular jsGetting started with angular js
Getting started with angular js
 
Rails + Webpack
Rails + WebpackRails + Webpack
Rails + Webpack
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1
 

Viewers also liked

Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerErik Isaksen
 
Microservices y la era Post Industrial de la Web
Microservices y la era Post Industrial de la WebMicroservices y la era Post Industrial de la Web
Microservices y la era Post Industrial de la WebRoberto Allende
 
High Performance Web Components
High Performance Web ComponentsHigh Performance Web Components
High Performance Web ComponentsSteve Souders
 
O'Reilly Fluent, Web Components Enterprise
O'Reilly Fluent, Web Components EnterpriseO'Reilly Fluent, Web Components Enterprise
O'Reilly Fluent, Web Components EnterpriseMediaMath
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web componentImam Raza
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureKelly Goetsch
 
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
 
Dockercon State of the Art in Microservices
Dockercon State of the Art in MicroservicesDockercon State of the Art in Microservices
Dockercon State of the Art in MicroservicesAdrian Cockcroft
 

Viewers also liked (9)

Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
Microservices y la era Post Industrial de la Web
Microservices y la era Post Industrial de la WebMicroservices y la era Post Industrial de la Web
Microservices y la era Post Industrial de la Web
 
High Performance Web Components
High Performance Web ComponentsHigh Performance Web Components
High Performance Web Components
 
O'Reilly Fluent, Web Components Enterprise
O'Reilly Fluent, Web Components EnterpriseO'Reilly Fluent, Web Components Enterprise
O'Reilly Fluent, Web Components Enterprise
 
HTML5 Web Components
HTML5 Web ComponentsHTML5 Web Components
HTML5 Web Components
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Microservices + Oracle: A Bright Future
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright Future
 
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
 
Dockercon State of the Art in Microservices
Dockercon State of the Art in MicroservicesDockercon State of the Art in Microservices
Dockercon State of the Art in Microservices
 

Similar to Web components the future is here

Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 
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 ArrivedGil Fink
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017Matt Raible
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is HereGil Fink
 
Working with Shortcodes in WordPress
Working with Shortcodes in WordPressWorking with Shortcodes in WordPress
Working with Shortcodes in WordPresschaefele
 
Freelancer Weapons of mass productivity
Freelancer Weapons of mass productivityFreelancer Weapons of mass productivity
Freelancer Weapons of mass productivityGregg Coppen
 
Wordpress beyond blogging
Wordpress beyond bloggingWordpress beyond blogging
Wordpress beyond bloggingJulien Minguely
 
X tag with web components - joe ssekono
X tag with web components - joe ssekonoX tag with web components - joe ssekono
X tag with web components - joe ssekonoJoseph Ssekono
 
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Jazkarta, Inc.
 
Rapid WordPress theme development
Rapid WordPress theme developmentRapid WordPress theme development
Rapid WordPress theme developmentJonny Allbut
 
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 arrivedGil Fink
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform AppsFITC
 
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 arrivedGil Fink
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)François Massart
 
Azure Resource Manager templates: Improve deployment time and reusability
Azure Resource Manager templates: Improve deployment time and reusabilityAzure Resource Manager templates: Improve deployment time and reusability
Azure Resource Manager templates: Improve deployment time and reusabilityStephane Lapointe
 
Dojo javascript toolkit
Dojo javascript toolkit Dojo javascript toolkit
Dojo javascript toolkit Predhin Sapru
 
Training presentation.pptx
Training presentation.pptxTraining presentation.pptx
Training presentation.pptxNishchaiyaBayla1
 
How to create a local Android open source project mirror in 6 easy steps
How to create a local Android open source project mirror in 6 easy stepsHow to create a local Android open source project mirror in 6 easy steps
How to create a local Android open source project mirror in 6 easy stepsDeveo
 

Similar to Web components the future is here (20)

Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
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
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
Working with Shortcodes in WordPress
Working with Shortcodes in WordPressWorking with Shortcodes in WordPress
Working with Shortcodes in WordPress
 
Freelancer Weapons of mass productivity
Freelancer Weapons of mass productivityFreelancer Weapons of mass productivity
Freelancer Weapons of mass productivity
 
Wordpress beyond blogging
Wordpress beyond bloggingWordpress beyond blogging
Wordpress beyond blogging
 
X tag with web components - joe ssekono
X tag with web components - joe ssekonoX tag with web components - joe ssekono
X tag with web components - joe ssekono
 
Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)Theming websites effortlessly with Deliverance (CMSExpo 2010)
Theming websites effortlessly with Deliverance (CMSExpo 2010)
 
Rapid WordPress theme development
Rapid WordPress theme developmentRapid WordPress theme development
Rapid WordPress theme development
 
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
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Twig in the Wild
Twig in the WildTwig in the Wild
Twig in the Wild
 
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
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)
 
Azure Resource Manager templates: Improve deployment time and reusability
Azure Resource Manager templates: Improve deployment time and reusabilityAzure Resource Manager templates: Improve deployment time and reusability
Azure Resource Manager templates: Improve deployment time and reusability
 
Dojo javascript toolkit
Dojo javascript toolkit Dojo javascript toolkit
Dojo javascript toolkit
 
Fundamentals of HTML5
Fundamentals of HTML5Fundamentals of HTML5
Fundamentals of HTML5
 
Training presentation.pptx
Training presentation.pptxTraining presentation.pptx
Training presentation.pptx
 
How to create a local Android open source project mirror in 6 easy steps
How to create a local Android open source project mirror in 6 easy stepsHow to create a local Android open source project mirror in 6 easy steps
How to create a local Android open source project mirror in 6 easy steps
 

More from Gil Fink

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech SpeakerGil Fink
 
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 Gil Fink
 
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 arrivedGil Fink
 
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 ArrivedGil Fink
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speakerGil Fink
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service WorkersGil Fink
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular AnimationsGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angularGil Fink
 
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?Gil Fink
 
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 scriptGil Fink
 
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 scriptGil Fink
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2Gil Fink
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSGil Fink
 
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 databasesGil Fink
 
Biological modeling, powered by angular js
Biological modeling, powered by angular jsBiological modeling, powered by angular js
Biological modeling, powered by angular jsGil Fink
 
Whos afraid of front end databases?
Whos afraid of front end databases?Whos afraid of front end databases?
Whos afraid of front end databases?Gil Fink
 
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 scriptGil Fink
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScriptGil Fink
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSGil 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
 
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
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 

Recently uploaded

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Recently uploaded (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

Web components the future is here

  • 1. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Web Components - The Future is Here Gil Fink CEO and Senior Consultant, sparXys
  • 2. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek The Pyramid of Doom
  • 3. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek About Me • sparXys CEO and Senior consultant • ASP.NET/IIS Microsoft MVP • Co-author of Pro Single Page Application Development (Apress) • Co-author of 4 Microsoft Official Courses (MOCs)
  • 4. Agenda • The problems we face • Web Components APIs o Templates o Imports o Shadow DOM o Custom Elements • Libraries to the rescue Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
  • 5. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 1. Undescriptive Markup Markup Example
  • 6. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 2. Poor Separation of Concerns You want HTML, CSS and JavaScript to work together You end up with a mess The wiring gets in your way!
  • 7. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 3. No Native Templates • Store HTML in hidden DOM element and show it • Use script tag as a template holder: <script id=”myTemplate” type=”text/template”> <div> … </div> </script>
  • 8. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 4. No Bundling • You want to bundle a complex component The component includes HTML, CSS and JavaScript how would you do that? o Use a server side wrapping mechanism?
  • 9. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Web Components to the Rescue • A set of standards designed to componentize the web • Some general goals: Code Reuse Encapsulation Separation of Concerns Composition Theming Expressive Semantic
  • 10. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek The Web Components Standards •Reusable DOM fragmentsTemplates •Load HTML declarativelyImports •DOM encapsulationShadow DOM •Create your own elements Custom Elements
  • 11. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Setting The Environment • Browsers have only partial support for Web Components o So we use the webcomponents.js Polyfill for Web Components • Download: o https://github.com/webcomponents/webcomponentsjs/ o Or install using your favorite package manager (Bower, Nuget) • Make sure the Polyfill script runs first
  • 12. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Demo Setting the environment
  • 13. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Let’s Drill Down
  • 14. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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  • To use the template you need some JavaScript magic <template id=”myTemplate”> <div> … </div> </template>
  • 15. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Cloning a Template • Select the template and extract its content o Using its content property • 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);
  • 16. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Templates Demo
  • 17. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Imports • Load additional HTML documents o Without Ajax • A new type of link tag • Use the rel attribute with the import type: <link rel=”import” href=”myImport.html”>
  • 18. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 19. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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;
  • 20. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Imports Demo
  • 21. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 22. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 23. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 24. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Shadow DOM in The Browser <video src="media/myVideo.mp4" controls></video> <input type="date">
  • 25. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Show Shadow DOM Elements in Chrome Demo
  • 26. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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>’;
  • 27. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Styling Shadow DOM • :host and :host() pseudo-class • ::content pseudo-element <div name="myElement"> <style> :host { border: 1px solid lightgray; } </style> <template>...</template> </div>
  • 28. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Shadow DOM Demo
  • 29. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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’ });
  • 30. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 31. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Custom Elements – Usage • Use the element in your DOM: or use the createElement function: <my-input></my-input> var elm = document.createElement(‘my-input’);
  • 32. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek 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
  • 33. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Custom Elements Demo
  • 34. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek The Current State of Web Components • Still W3C Working Drafts • Browser support: http://caniuse.com/#search=web%20components • Main libraries: Polymer X-Tag
  • 35. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Polymer • Components library that is written and maintained by Google • Includes o Ability to build your own custom components o Ready to use web components • Polymer leverages the web components standard
  • 36. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Polymer Catalog • Full catalog that includes various ready to use components • You can look at the component categories here: https://elements.polymer-project.org/ • Support to Google material design and Google API components included
  • 37. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Creating Custom Elements in Polymer <dom-module id="contact-card"> <link rel="import" type="css" href="contact-card.css"> <template> <content></content> <iron-icon icon="star" hidden$="{{!starred}}"></iron-icon> </template> <script> Polymer({ is: 'contact-card', properties: { starred: Boolean } }); </script> </dom-module>
  • 38. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Using The Custom Elements in Polymer <contact-card starred> <img src="profile.jpg" alt="Gil's photo"> <span>Gil Fink</span> </contact-card>
  • 39. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Polymer Demo
  • 40. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek X-Tag • Components library that is supported by Microsoft • Includes only the ability to write your own custom components o Ready to use web components can be found in the Brick library • X-Tag leverages the web components standard
  • 41. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Creating Web Components in X-Tag xtag.register('x-myelement', { lifecycle: { created: function(){ // do something when the element is created } }, events: { focus: function(){ // do something when the element in focus } }, methods: { someMethod: function(){ // implementation } } });
  • 42. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek X-Tag Demo
  • 43. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Questions?
  • 44. Summary • Web Components are emerging standards that enables: • Encapsulation • Separation of Concerns • Element portability • And more • They are still in development • Taking the web one step forward! Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek
  • 45. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Resources • Download the slide deck: http://bit.ly/1OCOnbL • http://webcomponents.org/ https://www.polymer-project.org/1.0/ http://www.x-tags.org/ • My Blog – http://www.gilfink.net • Follow me on Twitter – @gilfink
  • 46. Join the conversation on Twitter: @DevWeek // #DW2016 // #DevWeek Thank You!