SlideShare a Scribd company logo
Web Components and Rails 
Boris Nadion 
boris@astrails.com 
@borisnadion
@borisnadion 
http://astrails.com
awesome web and mobile apps 
since 2005
1997
Web Components With Rails
bank
Active Desktop 
Microsoft
desktop widgets
tasks management app 
vanilla javascript + HTML running in IE4 on a desktop
innovation
mostly C/C++ until 2005
Ruby
Rails
bin
There are only 10 types of people in world: 
those who understand binary and those who don’t.
102 
types of people in web development
backend
frontend
html
html + css
html + css + javascript
full stack 
112
test 
what engineer are you?
2 recent memory leaks 
what did they blow?
server 
2 backend
server browser 
2 backend 
2 frontend
server browser 
2 backend 
2 frontend 
1 1 full stack
server browser 
2 backend 
2 frontend 
1 1 full stack 
designer/PM
2005
prototype.js + effects.js
$(…) with $$(…) 
$$ lookup is much more expensive than $
jQuery 
2006
Angular.js
ember.js
Backbone/Marionette
MVC / MVVM / MV*
class 
MyApp.SomeController 
extends 
Marionette.Controller 
show: 
(id) 
-­‐> 
App.mainRegion.show 
new 
MyApp.SomeView( 
model: 
App.request("somemodel:load", 
id) 
) 
class 
MyApp.SomeView 
extends 
Marionette.ItemView 
template: 
"templates/some/show" 
templateHelpers: 
-­‐> 
klass: 
=> 
if 
@model.has_something() 
then 
"some" 
else 
"nothing" 
initialize: 
=> 
@listenTo 
@model, 
"change", 
@render 
class 
Models.SomeModel 
extends 
Backbone.Model 
url: 
-­‐> 
Routes.somemodel_path(@get("id")) 
App.reqres.setHandlers 
"some 
model:load": 
(id) 
-­‐> 
res 
= 
new 
Model.SomeModel(id: 
id) 
res.fetch() 
res
document.registerElement
XFoo 
= 
document.registerElement('x-­‐foo') 
document.body.appendChild(new 
XFoo())
proto 
= 
Object.create(HTMLElement.prototype) 
document.registerElement(‘x-­‐foo’, 
prototype: 
proto)
lifecycle callbacks
proto 
= 
Object.create(HTMLElement.prototype) 
proto.createdCallback 
= 
-­‐> 
#... 
proto.attachedCallback 
= 
-­‐> 
#... 
proto.detachedCallback 
= 
-­‐> 
#... 
proto.attributeChangedCallback 
= 
(name, 
from, 
to) 
-­‐> 
#... 
XFoo 
= 
document.registerElement('x-­‐foo', 
prototype:proto)
encapsulate functionality
proto.createdCallback 
= 
-­‐> 
@addEventListener 
'click', 
(e) 
-­‐> 
alert('yeah')
photo.createdCallback 
= 
-­‐> 
@innerHTML 
= 
"<b>I'm 
bold 
and 
inside 
the 
x-­‐foo</b>"
Shadow Root
proto.createdCallback 
= 
-­‐> 
shadow 
= 
@createShadowRoot() 
shadow.innerHTML 
= 
"<b>I'm 
bold 
and 
inside 
the 
shadow 
root</b>"
Templates
<template 
id="mytemplate"> 
<style> 
p 
{ 
color: 
yellow; 
} 
</style> 
<p>I'm 
yellow 
in 
a 
shadow 
root</p> 
</template> 
proto.createdCallback 
= 
-­‐> 
template 
= 
document.querySelector('#mytemplate') 
clone 
= 
document.importNode(template.content, 
true) 
@createShadowRoot().appendChild(clone)
Polymer 
https://www.polymer-project.org/
<!-­‐-­‐ 
Define 
element 
-­‐-­‐> 
<polymer-­‐element 
name="my-­‐counter" 
attributes="counter"> 
<template> 
<style> 
/*...*/ 
</style> 
<div 
id="label"><content></content></div> 
Value: 
<span 
id="counterVal">{{counter}}</span><br> 
<button 
on-­‐tap="{{increment}}">Increment</button> 
</template> 
<script> 
Polymer({ 
counter: 
0, 
// 
Default 
value 
counterChanged: 
function() 
{ 
this.$.counterVal.classList.add('highlight'); 
}, 
increment: 
function() 
{ 
this.counter++; 
} 
}); 
</script> 
</polymer-­‐element> 
<!-­‐-­‐ 
Use 
element 
-­‐-­‐> 
<my-­‐counter 
counter="10">Points</my-­‐counter>
X-Tags 
http://x-tags.org/
xtag.register 
"x-­‐accordion", 
extends: 
"div" 
lifecycle: 
created: 
-­‐> 
inserted: 
-­‐> 
removed: 
-­‐> 
attributeChanged: 
-­‐> 
events: 
"click:delegate(x-­‐toggler)": 
-­‐> 
accessors: 
togglers: 
get: 
-­‐> 
set: 
(value) 
-­‐> 
methods: 
nextToggler: 
-­‐> 
previousToggler: 
-­‐>
Bosonic 
http://bosonic.github.io/
<element 
name="b-­‐hello-­‐world"> 
<style> 
</style> 
<template> 
<h3>Hello, 
world!</h3> 
<p>Lorem 
ipsum</p> 
</template> 
<script> 
({ 
createdCallback: 
function() 
{ 
var 
root 
= 
this.createShadowRoot(); 
root.appendChild(this.template.content.cloneNode(true)); 
} 
}); 
</script> 
</element>
Brick 
http://mozbrick.github.io/
Polymer 
https://www.polymer-project.org/
Web Components With Rails
polyfill 
support old browsers
<!-­‐-­‐ 
Polyfill 
Web 
Components 
support 
for 
older 
browsers 
-­‐-­‐> 
<script 
src="components/platform/platform.js"></script> 
<!-­‐-­‐ 
Import 
element 
-­‐-­‐> 
<link 
rel="import" 
href="google-­‐map.html"> 
<!-­‐-­‐ 
Use 
element 
-­‐-­‐> 
<google-­‐map 
lat="37.790" 
long="-­‐122.390"></google-­‐map>
lightweight CES 
https://github.com/WebReflection/document-register-element
• custom elements 
• html imports 
• templates 
• shadow root
Polymer Rails 
https://github.com/alchapone/polymer-rails
Web Components With Rails
// 
application.html 
//= 
require 
polymer/polymer 
//= 
require 
my-­‐navigation/my-­‐navigation 
// 
my-­‐navigation.html.erb 
<polymer-­‐element 
name="my-­‐navigation"> 
<template> 
<%= 
stylesheet_link_tag 
'my-­‐navigation/style'%> 
<ul 
class="navigation"> 
<li><a 
href="/">Home</a></li> 
<li><a 
href="/">Contacts</a></li> 
<li><a 
href="/">Blog</a></li> 
<li><a 
href="/">Twitter</a></li> 
<li><a 
href="/">Facebook</a></li> 
</ul> 
</template> 
<%= 
javascript_include_tag 
"my-­‐navigation/my-­‐navigation"%> 
</polymer-­‐element> 
// 
my-­‐navigation.coffee 
Polymer 
'my-­‐navigation' 
// 
style.sass 
:host 
display: 
block 
.navigation 
list-­‐style: 
none 
margin: 
0 
background: 
#fff 
# 
...
Should I use Polymer for my next project? 
https://news.ycombinator.com/item?id=7970781
encapsulation
clean up HTML
hide everything 
shadow DOM
HTML vs. MV*
frontend is cool again
thanks! 
Boris Nadion 
astrails.com/blog

More Related Content

KEY
Paris js extensions
PDF
The Beauty of Java Script
KEY
[Coscup 2012] JavascriptMVC
PDF
The Beauty Of Java Script V5a
PDF
Testing Web Applications with GEB
PDF
History of jQuery
PDF
Processing and Processing.js
PDF
Write Less Do More
Paris js extensions
The Beauty of Java Script
[Coscup 2012] JavascriptMVC
The Beauty Of Java Script V5a
Testing Web Applications with GEB
History of jQuery
Processing and Processing.js
Write Less Do More

What's hot (20)

PDF
¿Cómo de sexy puede hacer Backbone mi código?
PDF
Prototype & jQuery
PDF
HTML5 JavaScript APIs
KEY
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
PDF
Web Crawling with NodeJS
PDF
JavaScript & HTML5 - Brave New World
PDF
jQuery Basic API
PDF
kissy-past-now-future
PPTX
KISSY 的昨天、今天与明天
PDF
Introducere in web
PDF
Flask intro - ROSEdu web workshops
PDF
jQuery in 15 minutes
PDF
Learning jQuery in 30 minutes
PPTX
Advanced JavaScript
PDF
JavaScript 1.5 to 2.0 (TomTom)
PDF
Drupal, meet Assetic
PDF
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
ODP
Introduction to jQuery
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
PDF
jQuery: Nuts, Bolts and Bling
¿Cómo de sexy puede hacer Backbone mi código?
Prototype & jQuery
HTML5 JavaScript APIs
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Web Crawling with NodeJS
JavaScript & HTML5 - Brave New World
jQuery Basic API
kissy-past-now-future
KISSY 的昨天、今天与明天
Introducere in web
Flask intro - ROSEdu web workshops
jQuery in 15 minutes
Learning jQuery in 30 minutes
Advanced JavaScript
JavaScript 1.5 to 2.0 (TomTom)
Drupal, meet Assetic
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Introduction to jQuery
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
jQuery: Nuts, Bolts and Bling
Ad

Similar to Web Components With Rails (20)

PDF
Polymer - pleasant client-side programming with web components
PDF
Polymer & the web components revolution 6:25:14
PDF
Web components
PDF
Building a Secure App with Google Polymer and Java / Spring
PDF
Backbone.js - Michał Taberski (PRUG 2.0)
PDF
Introduction to Web Components
PDF
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
PDF
Polymer Web Framework - Swecha Boot Camp
PDF
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
KEY
Single Page Web Apps with Backbone.js and Rails
KEY
Prateek dayal backbonerails-110528024926-phpapp02
PDF
2014 03-25 - GDG Nantes - Web Components avec Polymer
PPTX
Cloud Endpoints _Polymer_ Material design by Martin Görner
PDF
PDF
MAppMechanic CodeLabs - PolymerJS Advanced Topics for Custom Elements
PDF
Make your Backbone Application dance
PPT
Intro to polymer-Devfest Yaoundé 2013
PDF
Introduction to Backbone.js for Rails developers
PPT
Backbone js
PDF
Polymer
Polymer - pleasant client-side programming with web components
Polymer & the web components revolution 6:25:14
Web components
Building a Secure App with Google Polymer and Java / Spring
Backbone.js - Michał Taberski (PRUG 2.0)
Introduction to Web Components
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer Web Framework - Swecha Boot Camp
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
Single Page Web Apps with Backbone.js and Rails
Prateek dayal backbonerails-110528024926-phpapp02
2014 03-25 - GDG Nantes - Web Components avec Polymer
Cloud Endpoints _Polymer_ Material design by Martin Görner
MAppMechanic CodeLabs - PolymerJS Advanced Topics for Custom Elements
Make your Backbone Application dance
Intro to polymer-Devfest Yaoundé 2013
Introduction to Backbone.js for Rails developers
Backbone js
Polymer
Ad

Recently uploaded (20)

PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administration Chapter 2
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Introduction to Artificial Intelligence
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
top salesforce developer skills in 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ai tools demonstartion for schools and inter college
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Softaken Excel to vCard Converter Software.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PTS Company Brochure 2025 (1).pdf.......
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administration Chapter 2
Odoo POS Development Services by CandidRoot Solutions
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Upgrade and Innovation Strategies for SAP ERP Customers
Introduction to Artificial Intelligence
Navsoft: AI-Powered Business Solutions & Custom Software Development
top salesforce developer skills in 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ai tools demonstartion for schools and inter college
CHAPTER 2 - PM Management and IT Context
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Softaken Excel to vCard Converter Software.pdf

Web Components With Rails