SlideShare une entreprise Scribd logo
1  sur  74
Télécharger pour lire hors ligne
Web Component
othree
othree
⚫ HappyDesigner, MozTW!
⚫ PhD Candidate @ NTUST, F2E @HTC
https://github.com/othreehttps://blog.othree.net/
othree
Why Web Component
Why
⚫ Rich Internet Applications!
⚫ More and more custom UI!
⚫ Complex → Modularize!
⚫ Reuse
Custom UI
What Developer Want
⚫ Modularize codes, markup and styles!
⚫ Simple and easy to reuse
What Developer Want
⚫ Use <magic-tag> and everything is done
Standards is Not
Enough
Standards Changes
too Slow
Let Web Extensible
Extensible Web
https://medium.com/the-future-of-the-web/2fcd1c1bb32!
http://extensiblewebmanifesto.org/!
http://www.w3.org/community/nextweb/
Web Component
Not just new markup language
Not one standard
The Standards
⚫ Shadow DOM!
⚫ Custom Element!
⚫ HTML Imports!
⚫ Template!
⚫ Scoped Style!
⚫ Mutation Observer … etc
Template
<template>
⚫ Provide reusable DOMNode!
⚫ Parse but not render!
⚫ Used to use <script type="text/template">!
⚫ Not parse at all
http://www.w3.org/TR/html5/scripting-1.html#the-template-element
<template id="sdom">!
<header>!
<h2>Eric</h2>!
</header>!
<section>!
<div>Digital Jedi</div>!
</section>!
<footer>!
<h4>footer text</h4>!
</footer>!
</template>
var tpl = document.getElementById('sdom');!
!
var dom = tpl.content.cloneNode(true);!
!
shadowRoot.appendChild(dom);
Shadow DOM
Shadow DOM
⚫ Hidden nodes in DOM tree!
⚫ Encapsulation!
⚫ Keep component simple!
⚫ Browser already have this feature
http://w3c.github.io/webcomponents/spec/shadow/
Take a Look
Use
⚫ Create shadow root!
⚫ appendChild to shadow root
var host = document!
.querySelector('.custom-component');!
!
var root = host.createShadowRoot();!
!
root.innerHTML = html_template_string;
DOM Tree
root
node
(host)
node
DOM Tree
Shadow Tree
root
node
(host)
Shadow
root
node
node
Get DOMNodes
⚫ querySelector, querySelectorAll on shadow root!
⚫ DOM API
Style
var html_template_string = !
!
'<style>div { color: red; }</style>' !
!
+ '<div>Click me!</div>';
Style in Shadow DOM
⚫ Scoped by default!
⚫ Possible to import separate css file!
⚫ Path issue
<option>
⚫ How to make custom element like <select>!
⚫ Fill content when using it
<select>
<option>
<magic-tag id="example4">!
<h2>Eric</h2>!
<h2>Bidelman</h2>!
<div>Digital Jedi</div>!
<h4>footer text</h4>!
</magic-tag>!
!
<template id="sdom">!
<header>!
<content select="h2"></content>!
</header>!
<section>!
<content select="div"></content>!
</section>!
<footer>!
<content select="h4:first-of-type"></content>!
</footer>!
</template>
<content>
⚫ <content> as insertion point!
⚫ CSS selector to select content
Custom Element
Custom Element
⚫ Define your element!
⚫ Use API
http://w3c.github.io/webcomponents/spec/custom/
<element>
⚫ No more in standards
Register Element
registerElement(‘x-button', {prototype: xButtonProto});
element name options
prototype extend
Custom Element Name
⚫ Custom element’s name should have “-”!
⚫ ex: x-button, my-slider!
⚫ With “-”, element don’t know by browser will treat as
unresolved element, otherwise it will be unknown
element
Unresolved
⚫ :unresolved can use to hide/style unresolved
elements!
⚫ Avoid FOUT
Custom Prototype
⚫ Inherit from HTMLElement.prototype!
⚫ Add lifecycle callbacks
Element Lifecycle
⚫ Define in custom element standard!
⚫ created!
⚫ attached!
⚫ detatched!
⚫ attributeChanged
https://www.w3.org/Bugs/Public/show_bug.cgi?id=24314
var doc = document.currentScript.ownerDocument;!
!
var xButtonProto = Object.create(HTMLElement.prototype);!
!
!
xButtonProto.createdCallback = function () {!
var root = this;!
var host = this.webkitCreateShadowRoot();!
//host blah blah ...!
};!
!
!
document.registerElement(‘x-button',!
{prototype: xButtonProto}!
);
HTML Imports
Imports
⚫ Import more resources for future use!
⚫ Images, Style, Scripts…etc!
⚫ Web Component
http://www.w3.org/TR/html-imports/
<link rel="import" href="path/to/component.html">
<script>
⚫ `document` is importer!
⚫ Easy to work with document!
⚫ How to get its self!
⚫ ex: <template> in importee document
importer importee
document document
document.registerElement!
!
//register on importer
<link rel="import"!
href="…" />
importer importee
document document
<template>!
<blah />!
</template>
<link rel="import"!
href="…" />
importer importee
document document
<template>!
<blah />!
</template>!
!
<script>!
!
// How to get template?!
!
</script>
<link rel="import"!
href="…" />
document.currentScript.ownerDocument;
currentScript
⚫ HTML5 API!
⚫ For 3rd party widgets to locate <script> position
http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-currentscript
importer importee
document document.currentScript
<template>!
<blah />!
</template>!
!
<script>!
!
document.currentScript!
.ownerDocument!
!
</script>
<link rel="import"!
href="…" />
All Together
Demo
https://github.com/othree/web-component-test
Libs
X-Tag
⚫ by Mozilla!
⚫ Easy to create custom element
http://www.x-tags.org/
Brick
⚫ by Mozilla!
⚫ Repository for Custom-UI build by X-Tag
http://mozilla.github.io/brick/
Polymer
⚫ by Google!
⚫ Application build upon Web Component!
⚫ Polyfills!
⚫ Share with X-Tag
http://www.polymer-project.org/
more..
⚫ Semantic!
⚫ Accessibility!
⚫ Internationalization!
⚫ Security!
⚫ Performance!
⚫ OS Native UI…
https://www.youtube.com/watch?v=e29D1daRYrQ
Q&A
> B

Contenu connexe

Tendances

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
Imam Raza
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
Rich Bradshaw
 

Tendances (20)

Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
Web Components
Web ComponentsWeb Components
Web Components
 
Web components the future is here
Web components   the future is hereWeb components   the future is here
Web components the future is here
 
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
 
jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013jQuery Conference Austin Sept 2013
jQuery Conference Austin Sept 2013
 
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
 
HTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi LHTML5 Introduction by Dhepthi L
HTML5 Introduction by Dhepthi L
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Web Components: What, Why, How, and When
Web Components: What, Why, How, and WhenWeb Components: What, Why, How, and When
Web Components: What, Why, How, and When
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned
 
Web Components
Web ComponentsWeb Components
Web Components
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Mdst 3559-02-10-jquery
Mdst 3559-02-10-jqueryMdst 3559-02-10-jquery
Mdst 3559-02-10-jquery
 
Jquery mobile
Jquery mobileJquery mobile
Jquery mobile
 
Introduction to jquery mobile with Phonegap
Introduction to jquery mobile with PhonegapIntroduction to jquery mobile with Phonegap
Introduction to jquery mobile with Phonegap
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
jQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days TorontojQuery For Developers Stack Overflow Dev Days Toronto
jQuery For Developers Stack Overflow Dev Days Toronto
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Mini-Training: Javascript Patterns
Mini-Training: Javascript PatternsMini-Training: Javascript Patterns
Mini-Training: Javascript Patterns
 

En vedette

Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brick
yongwoo Jeon
 

En vedette (9)

Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brick
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Front end performance analysis v0.6
Front end performance analysis v0.6Front end performance analysis v0.6
Front end performance analysis v0.6
 
Web Components - Part.I, @KIG 30th
Web Components - Part.I, @KIG 30thWeb Components - Part.I, @KIG 30th
Web Components - Part.I, @KIG 30th
 
Polymer Codelab: Before diving into polymer
Polymer Codelab: Before diving into polymerPolymer Codelab: Before diving into polymer
Polymer Codelab: Before diving into polymer
 
[Sencha 엔터프라이즈 웹애플리케이션 세미나] 기업 환경에서 HTML5 도입전략 소개
[Sencha 엔터프라이즈 웹애플리케이션 세미나] 기업 환경에서 HTML5 도입전략 소개[Sencha 엔터프라이즈 웹애플리케이션 세미나] 기업 환경에서 HTML5 도입전략 소개
[Sencha 엔터프라이즈 웹애플리케이션 세미나] 기업 환경에서 HTML5 도입전략 소개
 
네이티브 웹앱 기술 동향 및 전망
네이티브 웹앱 기술 동향 및 전망네이티브 웹앱 기술 동향 및 전망
네이티브 웹앱 기술 동향 및 전망
 
알아봅시다, Polymer: Web Components & Web Animations
알아봅시다, Polymer: Web Components & Web Animations알아봅시다, Polymer: Web Components & Web Animations
알아봅시다, Polymer: Web Components & Web Animations
 
우리가 몰랐던 크롬 개발자 도구
우리가 몰랐던 크롬 개발자 도구우리가 몰랐던 크롬 개발자 도구
우리가 몰랐던 크롬 개발자 도구
 

Similaire à Web Component

Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
Mats Bryntse
 

Similaire à Web Component (20)

Web Components v1
Web Components v1Web Components v1
Web Components v1
 
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
 
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 - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
 
Frontend for developers
Frontend for developersFrontend for developers
Frontend for developers
 
2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio2016 stop writing javascript frameworks by Joe Gregorio
2016 stop writing javascript frameworks by Joe Gregorio
 
Web components
Web componentsWeb components
Web components
 
MVC 6 - Tag Helpers and View Components
MVC 6 - Tag Helpers and View ComponentsMVC 6 - Tag Helpers and View Components
MVC 6 - Tag Helpers and View Components
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application Platform
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
 
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
 
IE8 Dev Overview_pp2003
IE8 Dev Overview_pp2003IE8 Dev Overview_pp2003
IE8 Dev Overview_pp2003
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Shortcodes vs Widgets: Which one and how?
Shortcodes vs Widgets: Which one and how?Shortcodes vs Widgets: Which one and how?
Shortcodes vs Widgets: Which one and how?
 
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
 

Plus de 偉格 高 (14)

node ffi
node ffinode ffi
node ffi
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Mobile web application
Mobile web applicationMobile web application
Mobile web application
 
this
thisthis
this
 
Web Developer Tools for ICOS 2013
Web Developer Tools for ICOS 2013Web Developer Tools for ICOS 2013
Web Developer Tools for ICOS 2013
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
Vim Plugin Deployment
Vim Plugin DeploymentVim Plugin Deployment
Vim Plugin Deployment
 
WAI-ARIA is More Than Accessibility
WAI-ARIA is More Than AccessibilityWAI-ARIA is More Than Accessibility
WAI-ARIA is More Than Accessibility
 
WAI-ARIA
WAI-ARIAWAI-ARIA
WAI-ARIA
 
TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單
 
Html5 New Features
Html5 New FeaturesHtml5 New Features
Html5 New Features
 
Base2
Base2Base2
Base2
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Web Component