BOOSTING YOUR 
PRODUCTIVITY 
Backbone & RactiveJS 
Gabriel Zigolis
@zigolis 
Front-End Architect at Arezzo ecommerces
SCHEDULE 
• Getting to know Backbone 
• Be Ractive 
• Everybody together (but separated) 
• Yeah, today is code day, babe!
“Gives structure to web applications 
by providing models, collections 
and views to consume API over 
a RESTful JSON interface.” 
backbonejs.org 
BACKBONEJS
USE WHY 
BACKBONE?
BECAUSE 
APPS 
THE 
UP 
GREW
NEEDING 
Organization 
Architecture 
Modularization 
MORE
CHARACTERISTICS 
• Powerful Javascript LIB 
• Adaptable, inspired on MV* pattern 
• Modern, widely used in SPA 
• Completely skinny, bitch! Just 6.5kb.
WHO IS USING IT?
OK, LET’S SEE SOME 
C0D10101
Collection 
var ArticleCollection = Backbone.Collection.extend({ 
url: '/articles', 
model: ArticleModel 
}); 
return ArticleCollection;
Model 
var ArticleModel = Backbone.Model.extend({ 
getTitle: function() { 
return this.get('title'); 
} 
}); 
return ArticleModel;
View 
var AppView = Backbone.View.extend({ 
template: _.template( $('#tmp-article-list').html() ), 
el: '.main', 
initialize: function () { 
this.collection = new Collection(); 
this.collection.fecth(); 
this.listenTo(this.collection, 'sync', this.render); 
}, 
render: function() { 
this.$('.list-group').html(this.template({ 
'collection' : this.collection 
})); 
} 
}); 
return AppView;
_.template 
<div class="main"> 
<ul class="list-group"> 
<script type="text/html" id="tmp-article-list"> 
<% collection.each(function(model){ %> 
<li> 
<a href="#article/<%= model.id %>" class="list-group-item"> 
<%= model.getTitle() %> 
</a> 
</li> 
<% }); %> 
</script> 
</ul> 
</div>
COOL Now we have this
WE WANT BUT 
MORE
YES WE CAN! 
• Interactivity 
• Two-way binding 
• Animations 
• SVG manipulation 
• {{Mustache}}
KEEPING 
EVERYTHING 
SIMPLE
ELEGANT AND 
PRODUCTIVE
NICE TO MEET YOU 
I’m Ractive.js
“It's a JavaScript library for building 
reactive user interfaces in a way that 
doesn't force you into a particular 
framework's way of thinking.” 
ractivejs.org 
RACTIVEJS
USE WHY 
RACTIVE?
MORE 
BECAUSE 
WE WANT 
• Productivity 
• Friendly code 
• Data binding 
• Support to animations
AND 
THE BESTOF
CHARACTERISTICS 
• A kind of magic Javascript LIB 
• Data-binding (a beautiful declarative syntax) 
• Flexible and performant animations and transitions 
• {{Mustache}} template system "yay"
IT? 
WHO DID
WHO'S BEEN MAINTAINING IT?
OK, LET’S TRY 
SOMETHING 
?
TWO WAY 
BINDING 
DATA
Ractive 
var ractive = new Ractive({ 
el: '#output', 
template: '#tmp-name' 
});
{{ template }} 
<label for="name"> 
Enter your name: 
</label> 
<input id="name" value='{{name}}'> 
<p>Hello {{name}}, I am Ractive</p>
AND 
THEMAGIC HAPPENS
PROXIES EVENTS
Ractive 
var ractive = new Ractive({ 
el: '#output', 
template: '#tmp-proxy' 
}); 
ractive.on('hello', function( event ) { 
alert('hello there!'); 
});
{{ template }} 
<button on-click='hello'>Hello!</button>
RETURNS THIS 
AND IT
BIT MORE 
WITH A 
LITTLE 
C0D10101 
WE CAN DO AMAZING THINGS!
LIST TODO
IT’S SO 
YES, 
NICE
COOL, NOW LET’S MIX 
BACKBONE 
& 
RACTIVE
RACTIVE 
A MVC LIB 
IS NOT 
WE NEED TO ADD AN ADAPTOR 
https://github.com/ractivejs/ractive-adaptors-backbone
We must render the view 
ractive = new Ractive({ 
el: '#output', 
template: '#tmp-thumbs', 
adaptors: [ 'Backbone' ] 
}); 
and set the adaptor
Now we can write the 
collection 
Thumbs = Backbone.Collection.extend({ 
model: Thumb 
});
And the model 
Thumbs = Backbone.Model.extend({ 
getThumb: function() { 
return this.get('thumb'); 
} 
});
Also, we can call http request 
xhr = new XMLHttpRequest(); 
xhr.open( 'get', '/thumbs' ); 
xhr.send();
And finally, to show 
on the view 
<ul class='thumbnails'> 
{{#thumbs}} 
<li> 
<img src='/assets/img/{{thumb}}'> 
</li> 
{{/thumbs}} 
</ul>
LOOK AT 
WOW 
THIS
THANKS 
THAT'S 
ALL, FOLKS 
A LOT 
GITHUB 
SLIDESHARE 
SPEAKERDECK 
/zigolis 
@zigolis 
Front-End Architect at Arezzo ecommerces

Boosting Your Productivity, with Backbone & RactiveJS