SlideShare a Scribd company logo
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'));
  }
});
Web Components + Backbone: a Game-Changing Combination
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

PPTX
React Native
PPT
Google Maps in Android
DOC
Map reduce hdfs
PPTX
빠르게훓어보는 Node.js와 Vert.x
PDF
Real World Web components
PDF
Web Components and Modular CSS
PDF
Components now!
React Native
Google Maps in Android
Map reduce hdfs
빠르게훓어보는 Node.js와 Vert.x
Real World Web components
Web Components and Modular CSS
Components now!

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

PPTX
Web Components: The Future of Web Development is Here
PDF
Introduction to Web Components
PPTX
Web component
PDF
Web Component
PDF
Web components the future is here
PPTX
Rawnet Lightning Talk - Web Components
PPTX
Web Components: The Future of Web Development is Here
PDF
«Разрушаем Вавилонскую Башню WWW с помощью веб-компонент»​
PDF
Front-end tower of Babylon
PDF
Web components are the future of the web - Take advantage of new web technolo...
PDF
2014 03-25 - GDG Nantes - Web Components avec Polymer
PPTX
Web components. Compose the web.
PDF
Web component driven development
PPTX
Web components Introduction
PDF
Web components
PDF
Webcomponents v2
PDF
The Time for Vanilla Web Components has Arrived
PDF
Build Reusable Web Components using HTML5 Web cComponents
PPTX
web_components_workshop.pptx
PDF
Web components - An Introduction
Web Components: The Future of Web Development is Here
Introduction to Web Components
Web component
Web Component
Web components the future is here
Rawnet Lightning Talk - Web Components
Web Components: The Future of Web Development is Here
«Разрушаем Вавилонскую Башню WWW с помощью веб-компонент»​
Front-end tower of Babylon
Web components are the future of the web - Take advantage of new web technolo...
2014 03-25 - GDG Nantes - Web Components avec Polymer
Web components. Compose the web.
Web component driven development
Web components Introduction
Web components
Webcomponents v2
The Time for Vanilla Web Components has Arrived
Build Reusable Web Components using HTML5 Web cComponents
web_components_workshop.pptx
Web components - An Introduction
Ad

More from Andrew Rota (17)

PDF
Integrating React.js Into a PHP Application: Dutch PHP 2019
PDF
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
PDF
Getting Started with GraphQL && PHP
PDF
Tutorial: Building a GraphQL API in PHP
PPTX
Building a GraphQL API in PHP
PDF
Ten practical ways to improve front-end performance
PDF
Component Based UI Architectures for the Web
PDF
Client-Side Performance Monitoring (MobileTea, Rome)
PDF
Integrating React.js Into a PHP Application
PDF
Effectively Monitoring Client-Side Performance
PDF
UI Rendering at Wayfair
PDF
Better PHP-Frontend Integration with Tungsten.js
PDF
Tungsten.js: Building a Modular Framework
PDF
Why Static Type Checking is Better
PDF
An Exploration of Frameworks – and Why We Built Our Own
PDF
The Complementarity of React and Web Components
PDF
Bem methodology
Integrating React.js Into a PHP Application: Dutch PHP 2019
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Getting Started with GraphQL && PHP
Tutorial: Building a GraphQL API in PHP
Building a GraphQL API in PHP
Ten practical ways to improve front-end performance
Component Based UI Architectures for the Web
Client-Side Performance Monitoring (MobileTea, Rome)
Integrating React.js Into a PHP Application
Effectively Monitoring Client-Side Performance
UI Rendering at Wayfair
Better PHP-Frontend Integration with Tungsten.js
Tungsten.js: Building a Modular Framework
Why Static Type Checking is Better
An Exploration of Frameworks – and Why We Built Our Own
The Complementarity of React and Web Components
Bem methodology
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Approach and Philosophy of On baking technology
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Approach and Philosophy of On baking technology
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

Web Components + Backbone: a Game-Changing Combination