SlideShare a Scribd company logo
Webcomponents
Everything is AWESOME!
Components
“An individual software component is a software
package, a web service, a web resource, or a
module that encapsulates a set of related functions
(or data).”
Component-based software engineering
Wikipedia
Components
● encapsulation
● reusability
● communication via interfaces
Components
● encapsulation
● reusability
● communication via interfaces
Today: components for the web ~= jquery plugins
Components
Example: Lightbox http://lokeshdhakar.com/projects/lightbox2/
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/lightbox.min.js"></script>
<link href="css/lightbox.css" rel="stylesheet" />
<a href="img/image-1.jpg" data-lightbox="i1" data-title="My caption">
<img src="img/image-1.jpg">
</a>
<a href="img/image-2.jpg" data-lightbox="i1" data-title="My caption2">
<img src="img/image-2.jpg">
</a>
Components
Example: Lightbox http://lokeshdhakar.com/projects/lightbox2/
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/lightbox.min.js"></script>
<link href="css/lightbox.css" rel="stylesheet" />
<a href="img/image-1.jpg" data-lightbox="i1" data-title="My caption">
<img src="img/image-1.jpg">
</a>
<a href="img/image-2.jpg" data-lightbox="i1" data-title="My caption2">
<img src="img/image-2.jpg">
</a>
But I’m using YUI :(
three request?
HTML Captions?
Components
Example: Lightbox
<link rel=”import” href=”//cdn.net/elements/lightbox.html”>
<lightbox-images>
<a href=”img/image-1.jpg”>
<figure>
<img src=”img/image-1.jpg”>
<figcaption><b>Lorem</b> Ipsum!</figcaption>
</figure>
</a>
</lightbox-images>
Components
Example: prism.js
Components
Example: prism.js
Components
Example: prism.js
span { display:block }
ShadowDOM - encapsulation
Shadow DOM
<div id=”foo”>Light DOM</div>
<script>
var foo = document.querySelector(‘#foo’);
shadow = foo.createShadowRoot();
shadow.innerHTML = “Shadow DOM”;
</script>
http://rszaloki.github.io/webcomponents/shadow_dom/index.html
Shadow DOM
Shadow DOM
Shadow host =
has a shadow root
Normal DOM under the
shadow host =
Light DOM
The content of a shadow host isn’t
rendered; the content of the
shadow root is rendered instead.
<div id="lego-name">
<img src="img/emmet.jpg">
<a href="">EMMET</a>
<p>An ordinary...</p>
<input type="text"
value="5"
is="x-rating">
</div>
<content select="img"></co
<content select="a"></cont
<hr>
<button>Select</button>
<content></content>
<script>
var foo = document.querySelector(‘#lego-name);
shadow = foo.createShadowRoot();
shadow.innerHTML = “ ”;
</script>
<div id="lego-name">
<img src="img/emmet.jpg">
<a href="">EMMET</a>
<p>An ordinary...</p>
<input type="text"
value="5"
is="x-rating">
</div>
<style>
:host {
text-align:center;
display:inline-block;
width:200px;
...
}
:host a
::content a {
font-family: impact;
font-size:30px;
color:green;
}
</style>
<input is=”x-rating”
value=”2”>
<input is=”x-rating”
value=”2”
readonly>
<style>
:host {
border:0;
color:black;
}
:host([readonly]) button {
display:none
}
</style>
<label>Rating: </label>
<button id="dec">-</button>
<span id="value"></span>
<button id="inc">+</button>
New selectors in the shadow:
● :host, :host(.selector), :host(:hover)
● ::content
● :host-context(.selector)
http://rszaloki.github.io/webcomponents/shadow_dom/index.html
Shadow DOM
Pierce through the boundary:
● ::shadow
selects the elements shadow root
● /deep/
ignores the boundary
http://rszaloki.github.io/webcomponents/shadow_dom/index.html
Shadow DOM
● abort
● error
● select
● change
● load
http://rszaloki.github.io/webcomponents/shadow_dom/index.html
Shadow DOM
● reset
● resize
● scroll
● selectstart
Events that are always
stopped at the boundary:
Others are retargeted:
the event is changed, to
look like, they’ve come
from the host element
Custom Elements - reuse
Custom elements
var LegoName = document.registerElement('lego-name');
var e1 = new LegoName();
var e2 = document.createElement('lego-name');
document.body.appendChild(e1);
document.body.appendChild(e2);
<lego-name></lego-name>
http://rszaloki.github.io/webcomponents/custom_elements/index.html
Custom elements
Lifecycle events:
● createdCallback
● attachedCallback
● detachedCallback
● attributeChangedCallback
http://rszaloki.github.io/webcomponents/custom_elements/index.html
Custom elements
var LNameProto = Object.create(HTMLElement.prototype);
LNameProto.createdCallback = function(){
this.innerHTML = “Hello!”
}
var LName = document.registerElement('lego-name',{
prototype:LNameProto
});
<lego-name></lego-name>
<lego-name>Hello</lego-name>
- source
- DOM
Custom elements
document.registerElement('lego-name', {
prototype: prototype object,
"extends":’li’
});
<li is=”lego-name”>
http://rszaloki.github.io/webcomponents/custom_elements/index.html
HTML Import
<link rel="import" href="assets.html"
onload="render()" id="assets">
...
<script>
function render(){
var content = document.getElementById('assets').import;
document.body.innerHTML = content;
}
</script>
http://rszaloki.github.io/webcomponents/import/index.html
HTML Import
● imports load asynchronous
● same-origin policy!
● javascript in the import
○ global object is the window
○ document is the window.document
○ importDoc = document.currentScript.ownerDocument;
importDoc.querySelector(‘template’);
● scripts inside the imports are blocks the parsing
● subimports
● the same import loads only once
HTML Template
<template>
<div>Everything is AWESOME!</div>
</template>
<script>
…
target.appendChild(
document.importNode(
template.content,true));
</script>
http://rszaloki.github.io/webcomponents/template/index.html
HTML Template
<template>
<div>Everything is AWESOME!</div>
</template>
<script>
…
target.appendChild(
document.importNode(
template.content,true));
</script>
http://rszaloki.github.io/webcomponents/template/index.html
Invisible and no
side effects!
Webcomponents
● encapsulation - Shadow DOM
● reusability - Custom Elements, HTML Import
● communication via interfaces - Attributes, Properties
● helpers - HTML Template
Can I use it?
Can I use it?
Custom Elements
HTML Templates
Shadow DOM
HTML Imports
● too much boilerplate
● no declarative api: <element>
● no easy way to let the users override
the default styles: parts, css variables
Polymer Project
Web Components
● Shadow DOM
● HTML Imports
● Custom Elements
Platform - polyfills
Polymer
DOM
● URL
● WeakMap
● Mutation Observers
Other
● Pointer Events
● Pointer Gestures
● Web Animations
Platform - polyfills
Polymer
create elements
Polymer
● declarative syntax
● dynamic templates
● two way data binding
● property observation
use elements
Polymer
● widget library
● UI and non-UI elements
● core elements + labs elements
tools
Polymer
Vulcanize: concatenate
the imported elements
designer: http://www.
polymer-project.
org/tools/designer/
Polymer
http://rszaloki.github.io/webcomponents/polymer-demo/lego.html
https://github.com/rszaloki/webcomponents
https://gist.github.com/ebidel/6314025
Thanks! Questions?
robert.szaloki@euedge.com / @rszaloki

More Related Content

PDF
Intro to ReactJS
PPTX
ReactJS for Beginners
PDF
Creating a WYSIWYG Editor with React
PPTX
PDF
React on Rails - RailsConf 2017 (Phoenix)
PPTX
ReactJs presentation
PDF
Railsconf 2017 - React & React Native a common codebase across native and web
PPTX
React, Flux and a little bit of Redux
Intro to ReactJS
ReactJS for Beginners
Creating a WYSIWYG Editor with React
React on Rails - RailsConf 2017 (Phoenix)
ReactJs presentation
Railsconf 2017 - React & React Native a common codebase across native and web
React, Flux and a little bit of Redux

What's hot (20)

PDF
Extending Kubernetes with Operators
PDF
Introduction to React & Redux
PDF
Using ReactJS in AngularJS
PPTX
React & redux
PDF
React.js+Redux Workshops
PPTX
React / Redux Architectures
PPTX
Angular Data Binding
PPTX
20180518 QNAP Seminar - Introduction to React Native
PPTX
Getting Started With ReactJS
PDF
React.js in real world apps.
PDF
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
PDF
React – Structure Container Component In Meteor
PPTX
React JS .NET
PPTX
Better web apps with React and Redux
PDF
React & Redux
PDF
AtlasCamp 2015: How HipChat ships at the speed of awesome
PPTX
A Brief Introduction to React.js
PPTX
Academy PRO: React JS. Redux & Tooling
ODP
Consume Spring Data Rest with Angularjs
PDF
Build and Distributing SDK Add-Ons
Extending Kubernetes with Operators
Introduction to React & Redux
Using ReactJS in AngularJS
React & redux
React.js+Redux Workshops
React / Redux Architectures
Angular Data Binding
20180518 QNAP Seminar - Introduction to React Native
Getting Started With ReactJS
React.js in real world apps.
Getting Started with Appcelerator Alloy - Cross Platform Mobile Development -...
React – Structure Container Component In Meteor
React JS .NET
Better web apps with React and Redux
React & Redux
AtlasCamp 2015: How HipChat ships at the speed of awesome
A Brief Introduction to React.js
Academy PRO: React JS. Redux & Tooling
Consume Spring Data Rest with Angularjs
Build and Distributing SDK Add-Ons
Ad

Viewers also liked (9)

PPTX
December10
PPS
Libro Electronico
PPT
POWERPOINT TIPS
PDF
المراجعة الثالثة مرحلة أولى 2010
PDF
A weaker version of continuity and a common fixed point theorem
PDF
Answer solution with analysis aieee 2011 aakash
PPT
Roots of equations
PPT
Administrative aide kpi
PDF
Formal Languages (in progress)
December10
Libro Electronico
POWERPOINT TIPS
المراجعة الثالثة مرحلة أولى 2010
A weaker version of continuity and a common fixed point theorem
Answer solution with analysis aieee 2011 aakash
Roots of equations
Administrative aide kpi
Formal Languages (in progress)
Ad

Similar to Frontend meetup 2014.06.25 (20)

PDF
Modern frontend development with VueJs
PDF
Web Components v1
PDF
Web Components + Backbone: a Game-Changing Combination
PPTX
Let's react - Meetup
PPT
PPTX
React + Redux Introduction
PDF
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
PDF
Desbravando Web Components
PDF
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
PDF
E2 appspresso hands on lab
PDF
E3 appspresso hands on lab
PDF
Creating lightweight JS Apps w/ Web Components and lit-html
PDF
Building iPhone Web Apps using "classic" Domino
PDF
Building Universal Web Apps with React ForwardJS 2017
PPTX
react-slides.pptx
PDF
Building and deploying React applications
PDF
Interoperable Component Patterns
PPTX
PDF
Advanced JQuery Mobile tutorial with Phonegap
PPTX
jQuery Fundamentals
Modern frontend development with VueJs
Web Components v1
Web Components + Backbone: a Game-Changing Combination
Let's react - Meetup
React + Redux Introduction
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Desbravando Web Components
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
E2 appspresso hands on lab
E3 appspresso hands on lab
Creating lightweight JS Apps w/ Web Components and lit-html
Building iPhone Web Apps using "classic" Domino
Building Universal Web Apps with React ForwardJS 2017
react-slides.pptx
Building and deploying React applications
Interoperable Component Patterns
Advanced JQuery Mobile tutorial with Phonegap
jQuery Fundamentals

More from EU Edge (16)

PDF
Synchronization with CouchDB and PouchDB
PDF
How I learned to Stop Worrying and Love the inline-block
PDF
Node.js
PDF
What is python
PDF
Advanced python
PDF
WebGL
PDF
Python alapu mobil backend
PDF
Res tful services
PDF
Open gl
PDF
Google glass a developers perspective
PDF
Google glass ict day presentation
PDF
How does it work the keyboard
PDF
Node webkit-meetup
PDF
Eu edge intro
PDF
Halado css eu edge
PDF
Miért jó oktatóanyagot készíteni?
Synchronization with CouchDB and PouchDB
How I learned to Stop Worrying and Love the inline-block
Node.js
What is python
Advanced python
WebGL
Python alapu mobil backend
Res tful services
Open gl
Google glass a developers perspective
Google glass ict day presentation
How does it work the keyboard
Node webkit-meetup
Eu edge intro
Halado css eu edge
Miért jó oktatóanyagot készíteni?

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Empathic Computing: Creating Shared Understanding

Frontend meetup 2014.06.25