SlideShare a Scribd company logo
Web Components
with Polymer
Jeff Tapper
Digital Primates
@jefftapper / @digitalprimates
Who am I?
• Senior Consultant at Digital Primates
– Building next generation client applications
• Developing Internet applications for 20 years
• Author of 12 books on Internet technologies
Who are you?
What are Web Components?
Web Components are an attempt to let
you write custom components that can be
used like this:
<body>
Sales:<br>
<my-super-cool-chart id="coolChart">
</my-super-cool-chart >
</body>
How do they work
• Web Components are a combination of
several w3c specifications
• Custom Elements
• Templates
• Shadow Dom
• HTML Imports
Creating Custom Elements
• Pure JavaScript
• X-tags: framework developed by Mozilla
• Polymer: framework developed by Google
• Each provides lifecycle events you can use
Creating in JavaScript
<my-tag></my-tag>
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function (){
this.textContent = 'This is my tag';
};
document.register('my-tag',{prototype:proto});
Component Lifecycle
• createdCallback()
• attachedCallback()
• detachedCallback()
• attributeChangedCallback()
X-tags
xtag.register('x-frankenstein', {
lifecycle:{
created: function(){
alert("Look! It's moving. It's alive!");
}
}
});
Xtags Lifecycle Events
• created
• inserted
• removed
• attributeChanged
Polymer
<polymer-element name="say-hi">
<script>
Polymer('say-hi',{
whatToSay: 'Hi',
created: function(){
// do something
}
})
</polymer-element>
Polymer Lifecycle Events
• created
• attached
• detached
• attributeChanged
What is Polymer?
A library built on top of Web Components.
Allows us to use Web Components today in modern browsers
which don’t yet support Web Components
3 main pieces
• A set of polyfills
• Web application framework
• Set of UI components
What are we covering?
Web Components, specifically:
What in the world are web components?
What problem are they trying to solve?
How do they work?
Can I actually use these things?
What does it mean to my app/development process?
Life on the Edge
Web Components are beyond leading edge.
As of this moment, they do not work in their entirety in all
browsers
A good portion of the functionality is available in Chrome
So, is it real?
Yes!!!
Web Component support is actually here today. Even
though they are not fully supported in all browsers,
Polymer and Polyfills allow use in most modern
browsers today
Where can I use this today?
Always finding the latest and greatest
http://jonrimmer.github.io/are-we-
componentized-yet/
Why are they important?
A few minor reasons you may like the idea, first:
Encapsulation
• Manageable Reuse
• Hiding complexity and implementation
• Dealing with duplicated IDs
• Dealing with CSS scoping / propagation
Ease of Distribution
Appropriate technology choices
• Markup in markup, not in code
How do they work?
Web Components are a series of Working draft
specifications:
• HTML Templates
– http://www.w3.org/TR/html-templates/
• Shadow DOM
– http://www.w3.org/TR/shadow-dom/
• Custom Elements
– http://www.w3.org/TR/custom-elements/
• HTML Imports
– http://www.w3.org/TR/html-imports/
Example Application
• Twitter-button
created by Zeno Rocha
source code available at
https://github.com/social-elements/twitter-button
http://localhost/poly/twitter-button-master
• Language Application
created by Michael Labriola
http://localhost/poly/
Templates
The concept of templates is prolific and nearly self-
explanatory. Their use takes a bit more effort:
Inactive DOM Fragment
Easily Clone-able
Easily Change-able
Templates
You define them with the template element
<template id="productTemplate">
<div>
<img src="">
<div class="name"></div>
<div class="description"></div>
</div>
</template>
This is parsed but it’s not active. It’s not rendered.
Shadow DOM
Shadow DOM is at the heart of the whole component
concepts
It’s encapsulation
Its used by the browsers today to implement their own
controls
Ultimately its about hiding implementation details and
exposing an interface
Shadow DOM
The name and the technical explanation
sometimes get in the way of the concept.
Put simply, the user sees this:
Photo by Photo by: Mark Kaelin/TechRepublic
Shadow DOM
The browser sees this:
Photo by Photo by: Mark Kaelin/TechRepublic
Shadow Host/Root
Rendering
The Shadow also forms a boundary. Styles don’t cross
unless you let them. So you to keep control of this area
Styles
This, by default, goes both ways… meaning we aren’t
worried about collisions.
Styles
Outside styles don’t
affect shadow content
Styles defined in here
are scoped locally
HTML Imports
• HTML imports are about importing and sharing HTML
content.
• Why? Well, reuse, it facilitates the reuse of templates
and provides us a fundamental need if we are going to
share an encapsulated chunk we might call a
component.
• <link rel="import" href="goodies.html">
HTML Imports
• Last word on this…
• Imports aren’t supported pretty much anywhere yet,
however, there are polyfills.
• Imports are blocking. So, your page will act as though it
needs this content before it can render.
Custom Elements
• Elements are the key to putting this together.
• Custom Elements are DOM elements that can be
defined by a developer.
• They are allowed to manage state and provide a
scriptable interface.
• In other words, they are the shell of what will become
our component
Custom Elements
• Defining a custom element like this:
<polymer-element extends="button" name="fancy-button">
</polymer-element>
• Allows you to use that custom element in your
own markup:
<div>
<fancy-button></fancy-button>
</div>
Custom Elements
• You can use the concepts we previously discussed,
templates, Shadow DOM, etc. from within a custom
element.
• Further, custom elements give you a set of Lifecycle
callbacks so you can know things like when you are
inserted into the DOM, removed and ready.
• This means you can define the visual aspects of a
custom element in mark up and the code in script.
Resources
• http://www.w3.org/wiki/WebComponents/
• http://www.polymer-project.org/
• @polymer – officical twitter of the polymer
project
• @digitalprimates
• @jefftapper

More Related Content

PPTX
Web Components
PDF
Introduction to Web Components
PPTX
Polymer and web component
PDF
Introduction to Web Components
PPT
Reaching for the Future with Web Components and Polymer
PPTX
Google Developer Group(GDG) DevFest Event 2012 Android talk
PDF
Custom Elements with Polymer Web Components #econfpsu16
PDF
Web Components
Web Components
Introduction to Web Components
Polymer and web component
Introduction to Web Components
Reaching for the Future with Web Components and Polymer
Google Developer Group(GDG) DevFest Event 2012 Android talk
Custom Elements with Polymer Web Components #econfpsu16
Web Components

What's hot (20)

PDF
Build Reusable Web Components using HTML5 Web cComponents
PPTX
How to build a web application with Polymer
PPTX
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
PPTX
Polymer
PDF
Introduction to polymer project
PDF
Web Components and Modular CSS
PPTX
Google Polymer Introduction
PDF
Booting up with polymer
PDF
Web Components Everywhere
PDF
Web components the future is here
PDF
Building a Secure App with Google Polymer and Java / Spring
PDF
Polymer
PPTX
Razor into the Razor'verse
PDF
Google Polymer Framework
PDF
Levent-Gurses' Introduction to Web Components & Polymer
PPTX
Goodbye JavaScript Hello Blazor
PDF
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
PDF
Web components
PPTX
Polymer / WebComponents
PPTX
The Truth About Your Web App's Performance
Build Reusable Web Components using HTML5 Web cComponents
How to build a web application with Polymer
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
Polymer
Introduction to polymer project
Web Components and Modular CSS
Google Polymer Introduction
Booting up with polymer
Web Components Everywhere
Web components the future is here
Building a Secure App with Google Polymer and Java / Spring
Polymer
Razor into the Razor'verse
Google Polymer Framework
Levent-Gurses' Introduction to Web Components & Polymer
Goodbye JavaScript Hello Blazor
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Web components
Polymer / WebComponents
The Truth About Your Web App's Performance
Ad

Viewers also liked (20)

PDF
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
PDF
HTML5 Web Components
PPTX
An Introduction to Web Components
PDF
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
PPTX
Your UX is not my UX
PDF
Just Make Stuff!
PDF
Goofy, Goodfellas and a Gardener: The Masters of Experience Design.
PDF
Programming Play
PDF
The Power of Play in Experimental Design with Claudia Chagüi De León
PDF
Here Be Dragons – Advanced JavaScript Debugging
PPTX
Managing Responsive Design Projects
PDF
When Clients Bare it All with David Allen
PDF
Creating a Smile Worthy World
PDF
How to SURVIVE the Creative Industry
PDF
I HATE YOUR GAME with Bob Heubel
PDF
The Shifting Nature of FED Role
PPT
! or ? with Chip Kidd
PDF
Putting your Passion into the Details
PDF
Empowering the “Mobile Web” with Chris Mills
PDF
Customizing Your Process
Lego for Software Engineers at Silicon Valley Code Camp 2011 (2010-10-10)
HTML5 Web Components
An Introduction to Web Components
Gamify Your Life – My Epic Quest of Awesome - Eric Boyd
Your UX is not my UX
Just Make Stuff!
Goofy, Goodfellas and a Gardener: The Masters of Experience Design.
Programming Play
The Power of Play in Experimental Design with Claudia Chagüi De León
Here Be Dragons – Advanced JavaScript Debugging
Managing Responsive Design Projects
When Clients Bare it All with David Allen
Creating a Smile Worthy World
How to SURVIVE the Creative Industry
I HATE YOUR GAME with Bob Heubel
The Shifting Nature of FED Role
! or ? with Chip Kidd
Putting your Passion into the Details
Empowering the “Mobile Web” with Chris Mills
Customizing Your Process
Ad

Similar to Web Components (20)

PPTX
Web components, so close!
PDF
The Time for Vanilla Web Components has Arrived
PDF
Web component driven development
PPTX
Html,CSS & UI/UX design
PPTX
02 From HTML tags to XHTML
PDF
Web Components at Scale, HTML5DevConf 2014-10-21
PPTX
Nsc 2013 06-17 - random rants on 2013
PDF
Web Components - The Future is Here
PPTX
Delhi student's day
PDF
Webcomponents TLV October 2014
PDF
Implementing a Symfony Based CMS in a Publishing Company
PDF
Introduction to Web Components & Polymer Workshop - JS Interactive
PDF
Web components - The Future is Here
PDF
Stencil the time for vanilla web components has arrived
PPTX
Introduction to Web Components & Polymer Workshop - U of I WebCon
PDF
Webcomponents v2
PPTX
Web components
PDF
Web components are the future of the web - Take advantage of new web technolo...
PPTX
Fundamentals of HTML5
PPTX
Ensuring Design Standards with Web Components
Web components, so close!
The Time for Vanilla Web Components has Arrived
Web component driven development
Html,CSS & UI/UX design
02 From HTML tags to XHTML
Web Components at Scale, HTML5DevConf 2014-10-21
Nsc 2013 06-17 - random rants on 2013
Web Components - The Future is Here
Delhi student's day
Webcomponents TLV October 2014
Implementing a Symfony Based CMS in a Publishing Company
Introduction to Web Components & Polymer Workshop - JS Interactive
Web components - The Future is Here
Stencil the time for vanilla web components has arrived
Introduction to Web Components & Polymer Workshop - U of I WebCon
Webcomponents v2
Web components
Web components are the future of the web - Take advantage of new web technolo...
Fundamentals of HTML5
Ensuring Design Standards with Web Components

More from FITC (20)

PPTX
Cut it up
PDF
Designing for Digital Health
PDF
Profiling JavaScript Performance
PPTX
Surviving Your Tech Stack
PDF
How to Pitch Your First AR Project
PDF
Start by Understanding the Problem, Not by Delivering the Answer
PDF
Cocaine to Carrots: The Art of Telling Someone Else’s Story
PDF
Everyday Innovation
PDF
HyperLight Websites
PDF
Everything is Terrifying
PDF
Post-Earth Visions: Designing for Space and the Future Human
PDF
The Rise of the Creative Social Influencer (and How to Become One)
PDF
East of the Rockies: Developing an AR Game
PDF
Creating a Proactive Healthcare System
PDF
World Transformation: The Secret Agenda of Product Design
PDF
The Power of Now
PDF
High Performance PWAs
PDF
Rise of the JAMstack
PDF
From Closed to Open: A Journey of Self Discovery
PDF
Projects Ain’t Nobody Got Time For
Cut it up
Designing for Digital Health
Profiling JavaScript Performance
Surviving Your Tech Stack
How to Pitch Your First AR Project
Start by Understanding the Problem, Not by Delivering the Answer
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Everyday Innovation
HyperLight Websites
Everything is Terrifying
Post-Earth Visions: Designing for Space and the Future Human
The Rise of the Creative Social Influencer (and How to Become One)
East of the Rockies: Developing an AR Game
Creating a Proactive Healthcare System
World Transformation: The Secret Agenda of Product Design
The Power of Now
High Performance PWAs
Rise of the JAMstack
From Closed to Open: A Journey of Self Discovery
Projects Ain’t Nobody Got Time For

Recently uploaded (20)

PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Digital Literacy And Online Safety on internet
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPT
tcp ip networks nd ip layering assotred slides
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
Introuction about WHO-FIC in ICD-10.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
Decoding a Decade: 10 Years of Applied CTI Discipline
introduction about ICD -10 & ICD-11 ppt.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Digital Literacy And Online Safety on internet
Sims 4 Historia para lo sims 4 para jugar
SASE Traffic Flow - ZTNA Connector-1.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
Module 1 - Cyber Law and Ethics 101.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Introuction about ICD -10 and ICD-11 PPT.pptx
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
SAP Ariba Sourcing PPT for learning material
Slides PPTX World Game (s) Eco Economic Epochs.pptx
tcp ip networks nd ip layering assotred slides
The Internet -By the Numbers, Sri Lanka Edition
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Unit-1 introduction to cyber security discuss about how to secure a system
Introuction about WHO-FIC in ICD-10.pptx

Web Components

  • 1. Web Components with Polymer Jeff Tapper Digital Primates @jefftapper / @digitalprimates
  • 2. Who am I? • Senior Consultant at Digital Primates – Building next generation client applications • Developing Internet applications for 20 years • Author of 12 books on Internet technologies
  • 4. What are Web Components? Web Components are an attempt to let you write custom components that can be used like this: <body> Sales:<br> <my-super-cool-chart id="coolChart"> </my-super-cool-chart > </body>
  • 5. How do they work • Web Components are a combination of several w3c specifications • Custom Elements • Templates • Shadow Dom • HTML Imports
  • 6. Creating Custom Elements • Pure JavaScript • X-tags: framework developed by Mozilla • Polymer: framework developed by Google • Each provides lifecycle events you can use
  • 7. Creating in JavaScript <my-tag></my-tag> var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function (){ this.textContent = 'This is my tag'; }; document.register('my-tag',{prototype:proto});
  • 8. Component Lifecycle • createdCallback() • attachedCallback() • detachedCallback() • attributeChangedCallback()
  • 10. Xtags Lifecycle Events • created • inserted • removed • attributeChanged
  • 12. Polymer Lifecycle Events • created • attached • detached • attributeChanged
  • 13. What is Polymer? A library built on top of Web Components. Allows us to use Web Components today in modern browsers which don’t yet support Web Components 3 main pieces • A set of polyfills • Web application framework • Set of UI components
  • 14. What are we covering? Web Components, specifically: What in the world are web components? What problem are they trying to solve? How do they work? Can I actually use these things? What does it mean to my app/development process?
  • 15. Life on the Edge Web Components are beyond leading edge. As of this moment, they do not work in their entirety in all browsers A good portion of the functionality is available in Chrome
  • 16. So, is it real? Yes!!! Web Component support is actually here today. Even though they are not fully supported in all browsers, Polymer and Polyfills allow use in most modern browsers today
  • 17. Where can I use this today?
  • 18. Always finding the latest and greatest http://jonrimmer.github.io/are-we- componentized-yet/
  • 19. Why are they important? A few minor reasons you may like the idea, first: Encapsulation • Manageable Reuse • Hiding complexity and implementation • Dealing with duplicated IDs • Dealing with CSS scoping / propagation Ease of Distribution Appropriate technology choices • Markup in markup, not in code
  • 20. How do they work? Web Components are a series of Working draft specifications: • HTML Templates – http://www.w3.org/TR/html-templates/ • Shadow DOM – http://www.w3.org/TR/shadow-dom/ • Custom Elements – http://www.w3.org/TR/custom-elements/ • HTML Imports – http://www.w3.org/TR/html-imports/
  • 21. Example Application • Twitter-button created by Zeno Rocha source code available at https://github.com/social-elements/twitter-button http://localhost/poly/twitter-button-master • Language Application created by Michael Labriola http://localhost/poly/
  • 22. Templates The concept of templates is prolific and nearly self- explanatory. Their use takes a bit more effort: Inactive DOM Fragment Easily Clone-able Easily Change-able
  • 23. Templates You define them with the template element <template id="productTemplate"> <div> <img src=""> <div class="name"></div> <div class="description"></div> </div> </template> This is parsed but it’s not active. It’s not rendered.
  • 24. Shadow DOM Shadow DOM is at the heart of the whole component concepts It’s encapsulation Its used by the browsers today to implement their own controls Ultimately its about hiding implementation details and exposing an interface
  • 25. Shadow DOM The name and the technical explanation sometimes get in the way of the concept. Put simply, the user sees this: Photo by Photo by: Mark Kaelin/TechRepublic
  • 26. Shadow DOM The browser sees this: Photo by Photo by: Mark Kaelin/TechRepublic
  • 29. The Shadow also forms a boundary. Styles don’t cross unless you let them. So you to keep control of this area Styles
  • 30. This, by default, goes both ways… meaning we aren’t worried about collisions. Styles Outside styles don’t affect shadow content Styles defined in here are scoped locally
  • 31. HTML Imports • HTML imports are about importing and sharing HTML content. • Why? Well, reuse, it facilitates the reuse of templates and provides us a fundamental need if we are going to share an encapsulated chunk we might call a component. • <link rel="import" href="goodies.html">
  • 32. HTML Imports • Last word on this… • Imports aren’t supported pretty much anywhere yet, however, there are polyfills. • Imports are blocking. So, your page will act as though it needs this content before it can render.
  • 33. Custom Elements • Elements are the key to putting this together. • Custom Elements are DOM elements that can be defined by a developer. • They are allowed to manage state and provide a scriptable interface. • In other words, they are the shell of what will become our component
  • 34. Custom Elements • Defining a custom element like this: <polymer-element extends="button" name="fancy-button"> </polymer-element> • Allows you to use that custom element in your own markup: <div> <fancy-button></fancy-button> </div>
  • 35. Custom Elements • You can use the concepts we previously discussed, templates, Shadow DOM, etc. from within a custom element. • Further, custom elements give you a set of Lifecycle callbacks so you can know things like when you are inserted into the DOM, removed and ready. • This means you can define the visual aspects of a custom element in mark up and the code in script.
  • 36. Resources • http://www.w3.org/wiki/WebComponents/ • http://www.polymer-project.org/ • @polymer – officical twitter of the polymer project • @digitalprimates • @jefftapper