SlideShare a Scribd company logo
1 of 67
Download to read offline
Web Components + Backbone
A Game-Changing Combination
Who Am I?
Andrew Rota
JavaScript Engineer,
JavaScript Modularity
By using small libraries –
components with a dedicated
purpose and a small surface
area – it becomes possible to
pick and mix, to swap parts of
our front end stack...
- Jimmy Breck-McKye, "The State of JavaScript in
2015"
Modularity in HTML == DOM Elements
<ul>
  <li>First Item</li>
  <li>Second Item</li>
</ul>
<ol>
  <li>First Item</li>
  <li>Second Item</li>
</ol>
<div class="header"></div>
<header></header>
<div id="nav"></div>
<nav></nav>
Libraries > frameworks?
- Jimmy Breck-McKye, "The State of JavaScript in
2015"
Libraries > frameworks?
- Jimmy Breck-McKye, "The State of JavaScript in
2015"
Native functionality > libraries
> frameworks.
- Me
But creating your own elements
isn't possible...
... until now.
Web Components
usher in a new era of
web development
based on
encapsulated and
interoperable custom
elements that extend
HTML itself. - Polymer Project
Web Components
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
Custom Elements
<my‐element>Hello World.</my‐element>
            
var MyElement = document.registerElement('my‐element', {
  prototype: Object.create(HTMLElement.prototype)
});
            
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
HTML Templates
<template id="my‐template">
    <p>Hello World.</p>
    <!‐‐ This image won't be downloaded on page load ‐‐>
    <img src="example.jpg" alt="Example">
</template>
document.importNode(
    document.getElementById('my‐template').content,
    true
);
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
HTML Imports
<link rel="import" href="/imports/my‐component.html">
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
Browser Shadow DOM
Shadow DOM
<div id="my‐element"></div><p>Light DOM.</p>
// Create Shadow Root
var s = document.getElementById('my‐element').createShadowRoot();
// Add Styles and Text
s.innerHTML += '<style>p { color: crimson; }</style>';
s.innerHTML += '<p>Shadow DOM.</p>';
Shadow DOM.
Light DOM.
<content>
<div id="my‐element"><p>Hello!</p></div>
var s = document.getElementById('my‐element').createShadowRoot();
s.innerHTML += '<p>Shadow DOM Start.</p>';
s.innerHTML += '<style>p { color: crimson; }</style>';
s.innerHTML += '<content></content>';
s.innerHTML += '<p>Shadow DOM End.</p>';
Shadow DOM Start.
Hello!
Shadow DOM End.
Web Component Technologies
Custom Elements
HTML Templates
HTML Imports
Shadow DOM
What Web Components Lack...
Application Structure
Server Interface
URL Router
Models/Collections + Events
...We Gain with Backbone
Application Structure
Server Interface
URL Router
Models/Collections + Events
Using Web
Component
Technologies
+
Backbone
Backbone + Custom Elements
document.registerElement('my‐custom‐element', {
  prototype: Object.create(HTMLElement.prototype)
});
Backbone.View.extend({
  tagName: 'my‐custom‐element'
});
Backbone + HTML Templates
Backbone.View.extend({
  template: document.importNode(
    document.getElementById('my‐template').content,
    true
  ),
  render: function() {
    this.el.innerHTML = this.template;
  }
});
Backbone + HTML Imports
<link rel="import" href="my‐custom‐component.html">
Backbone + Shadow DOM
Backbone.View.extend({
  initialize: function() {
    this.el.createShadowRoot();
  }
});
Using Web
Component
Technologies
+
Backbone
Using Web
Components
+
Backbone
polymer-project.org/docs/elements
x-tags.org
component.kitchen
customelements.io
Backbone View
+
Web Component
<paper‐toast>
<paper‐toast> API
<paper‐toast
  text="Your toast is ready!"
  duration="5000"
  autoCloseDisabled
  opened
></paper‐toast>
Element.show();
Element.dismiss();
Element.toggle();
Element.addEventListener('core‐overlay‐open‐completed', doSomething
Backbone.View.extend({
  tagName: 'paper‐toast',
  attributes: {
    text: 'Your toast is ready!',
    autoCloseDisabled: true,
    duration: '5000',
    opened: true
  },
  events: {
    'core‐overlay‐open‐completed': 'doSomething'
  },
  toggle: function() {
    this.el.toggle();
  }
});
<google‐map>
<google‐map> API
<google‐map
  zoom="10"
  latitude="42.3581"
  longitude="‐71.0636"
></google‐map>
Element.resize();
Element.clear();
Element.addEventListener('google‐map‐ready', doSomething);
Backbone.View.extend({
  tagName: 'google‐map',
  attributes: {
    latitude: '42.3581',
    longitude: '‐71.0636',
    zoom: '10'
  },
  events: {
    'google‐map‐ready': 'doSomething'
  },
  resize: function() {
    this.el.resize();
  }
});
Backbone.View.extend({
  initialize: function() {
    this.listenTo(this.model, 'change', this.moveMap );
  },
  tagName: 'google‐map',
  moveMap: function(model) {
    this.el.setAttribute('latitude', this.model.get('lat'));
    this.el.setAttribute('longitude', this.model.get('long'));
    this.el.setAttribute('zoom', this.model.get('zoom'));
  }
});
Building Web Components
for Backbone (or anything else)
├── hello‐world
├──── hello‐world.html
├──── hello‐world.js
└──── bower.json
            
<template id="my‐template">
  Hello, <content></content
</template>
<script src="hello‐world.js
var element = Object.create(HTMLElement.prototype);
element.createdCallback = function() {};
element.attachedCallback = function() {};
element.attributeChangedCallback = function(attr, oldVal, newVal) {}
element.detachedCallback = function() {};
document.registerElement('hello‐world', {
  prototype: element
});
<link
  rel="import"
  href="components/hello‐world/hello‐world.html
>
<!‐‐ [...] ‐‐>
<hello‐world>I'm a web component</
How It All Fits Together
Application + Components
Application
Component Component Component Component Component
Component Component Component Component Component
Component Component Component Component Component
Application + Components
Application + Components
Application + Components
< X >
< X >
Web Component All the Things??
<backboneconf‐app>
    <backboneconf‐menu></backboneconf‐menu>
    <backboneconf‐content></backboneconf‐content>
    <backboneconf‐footer></backboneconf‐footer>
</backboneconf‐app>
Probably Not (and that's OK)
I don't ever see us going all in
on Custom Elements for every
possible thing ... Use native
elements and controls when
possible and supplement with
custom elements.
- Joshua Peek, Github Programmer
Should I Componentize?
Does it encapsulate component-level logic?
Does it take the place of a native element?
Should it be portable?
Is it context independent?
Can the API be represented as attributes, methods, and events?
Small
Open for Extension
Documented
Unit Tested
Accessible
Idempotent
Best Practices
Can I Use???
Custom
Elements
HTML
Templates
HTML
Imports
Shadow
DOM
✓ ✓ ✓ ✓
✓ ✓ ✓ ✓
Flag ✓ Flag Flag
X ✓ X X
X X X X
Can I Use???
Custom
Elements
HTML
Templates
HTML
Imports
Shadow
DOM
✓ ✓ ✓ ✓
✓ ✓ ✓ ✓
✓ ✓ ✓ ✓
✓ ✓ ✓ ✓
✓ ✓ ✓ ✓
webcomponents.js
Towards a Component Driven Web
Thanks!
Resources
- WebComponents.org
- Web Components: A Tectonic Shift for Web Development by Eric Bidelman
- Web Components by Jarrod Overson and Jason Strimpel
- Ten Principles for Great General Purpose Web Components
Colophon
This presentation was built with Backbone.js, Shadow DOM, HTML
Templates, HTML Imports, and the Custom Element <slide‐content>
using Web Component Slides.

More Related Content

What's hot

BDD勉強会 第6回
BDD勉強会 第6回BDD勉強会 第6回
BDD勉強会 第6回
zakihaya
 

What's hot (20)

Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
BDD勉強会 第6回
BDD勉強会 第6回BDD勉強会 第6回
BDD勉強会 第6回
 
판교 개발자 데이 – 쉽고 안전한 Aws IoT 플랫폼 활용하기 – 이창수
판교 개발자 데이 – 쉽고 안전한 Aws IoT 플랫폼 활용하기 – 이창수판교 개발자 데이 – 쉽고 안전한 Aws IoT 플랫폼 활용하기 – 이창수
판교 개발자 데이 – 쉽고 안전한 Aws IoT 플랫폼 활용하기 – 이창수
 
WebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction PresentationWebAssembly WASM Introduction Presentation
WebAssembly WASM Introduction Presentation
 
Webpack slides
Webpack slidesWebpack slides
Webpack slides
 
High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016High-Performance JDBC Voxxed Bucharest 2016
High-Performance JDBC Voxxed Bucharest 2016
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
PWA 與 Service Worker
PWA 與 Service WorkerPWA 與 Service Worker
PWA 與 Service Worker
 
React Django Presentation
React Django PresentationReact Django Presentation
React Django Presentation
 
Api first design 개발의 선순환
Api first design 개발의 선순환Api first design 개발의 선순환
Api first design 개발의 선순환
 
[Open southcode] ios testing with appium
[Open southcode] ios testing with appium[Open southcode] ios testing with appium
[Open southcode] ios testing with appium
 
Lessons Learned from Using Next.js in Production
Lessons Learned from Using Next.js in ProductionLessons Learned from Using Next.js in Production
Lessons Learned from Using Next.js in Production
 
Swagger
SwaggerSwagger
Swagger
 
NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
Manage appium dependencies with -appium-home in appium 2.0
Manage appium dependencies with  -appium-home in appium 2.0Manage appium dependencies with  -appium-home in appium 2.0
Manage appium dependencies with -appium-home in appium 2.0
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Mobile Testing with Appium
Mobile Testing with AppiumMobile Testing with Appium
Mobile Testing with Appium
 

Similar to Web Components + Backbone: a Game-Changing Combination

Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25
EU Edge
 

Similar to Web Components + Backbone: a Game-Changing Combination (20)

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
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
handout-05b
handout-05bhandout-05b
handout-05b
 
handout-05b
handout-05bhandout-05b
handout-05b
 
React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix
 
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]
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25
 
Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25Webcomponents at Frontend meetup 2014.06.25
Webcomponents at Frontend meetup 2014.06.25
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
 
HTML5
HTML5HTML5
HTML5
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
 
A brave new web - A talk about Web Components
A brave new web - A talk about Web ComponentsA brave new web - A talk about Web Components
A brave new web - A talk about Web Components
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 

More from Andrew Rota

More from Andrew Rota (16)

Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
 
Getting Started with GraphQL && PHP
Getting Started with GraphQL && PHPGetting Started with GraphQL && PHP
Getting Started with GraphQL && PHP
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Component Based UI Architectures for the Web
Component Based UI Architectures for the WebComponent Based UI Architectures for the Web
Component Based UI Architectures for the Web
 
Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Effectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side PerformanceEffectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side Performance
 
UI Rendering at Wayfair
UI Rendering at WayfairUI Rendering at Wayfair
UI Rendering at Wayfair
 
Better PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.jsBetter PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.js
 
Tungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular FrameworkTungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular Framework
 
Why Static Type Checking is Better
Why Static Type Checking is BetterWhy Static Type Checking is Better
Why Static Type Checking is Better
 
An Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our OwnAn Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our Own
 
Bem methodology
Bem methodologyBem methodology
Bem methodology
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Web Components + Backbone: a Game-Changing Combination