SlideShare a Scribd company logo
Backbone the Good Parts
Renan Carvalho 
Carioca 
U2 fan 
Frustrated musician 
Beer Appreciator 
King of age of empires 
Love agile methods 
Front end developer at Chute 
Blog : rcarvalhojs.com 
Github : renancarvalho 
Twitter : rcarvalhojs 
Hate who says bad things about JS
The examples will be based on blogMv project 
https://github.com/blogmv/backbone-browserify 
More info http://blogmv.github.io
What’s the problem? 
What’s backbone? 
Keep data synchronized 
Complex code 
Spaghetti code 
Manage callbacks 
Ajax, XHR? (Impossible to remember the syntax) 
How to test it? :( - TDD? http://www.tddunlocked.com.br/
“Backbone is a mindset change.” 
Renan Carvalho 
What’s backbone?
And it’s also… 
Javascript library 
Based on MV* concept 
Lightweight (production version has 6.5kb) 
Depends on underscore 
Trust me, it’s awesome! 
What’s backbone?
What are you building?
A Helicopter…
…or a Helicopter?
For complex users interface 
Reusable code 
Build single page apps 
When you don’t know what kind of “helicopter” 
When to use? 
When to use it? 
Complex systems 
Good Integration with legacy code 
Simple systems 
Really performatic system 
If you’re under 18 
(Flying lollipop)
Router 
Url routing using (#home or /home) 
Application history
Backbone router 
Router.js
Backbone.history.start(), to start to track url (hashChanges) 
If you’d like to use html5 push state, just use Backbone.history.start({pushState: true}) 
Backbone router 
More examples : http://backbonejs.org/#Router
View 
Represents models data 
Handle user interaction (input events)
View 
render() - Convenction function for render view. Be 
careful with SRP 
el - Dom object, that will be used as the view reference 
(default is a <div>) 
$el - Jquery object that keeps the reference to el. 
initialize() - “Constructor” function for every backbone 
class 
events - Handle view events like ( click, change…) 
Backbone view
postComment.hbs 
Backbone view
postComment.js 
Backbone view
Example of bad 
implementation 
Backbone view
Example of good implementation 
Backbone view
Model 
Manage data. 
Validate data 
know where to send/get data 
Should be thin and beautiful
Model 
fetch() - get data from server 
save() - post/put data on server 
If the model has an id attribute, backbone will perform a put. 
get/set - get/set attributes on model 
parse - function called before backbone merge the server content with the model. 
validate - perform custom validations on model. Fired when save(), set or invoked. 
url - server endpoint (api), where model will perform the request 
More about backbone models: http://backbonejs.org/#Model 
Backbone model
Example of bad 
implementation 
Backbone model
comment.js 
Backbone model
Collection 
Basically “a lot of models 
together"
Collection 
fetch() - Exactly like model, get data from server. 
create() - Create a new model instance within a collection (save on 
server). 
push() - add a model at the end of the collection 
add - add a model into a collection, you can specify the position where 
the model will be added ( this.collection.add(new model(), {at : 8}); ) 
reset() - sets the collection with an array of models. 
More about backbone collection: http://backbonejs.org/#Collection 
Backbone collection
comment.js 
Backbone collection 
article.js
Events 
NOT CALLBACKS !!
Catalog of Events 
Backbone events
listenTo - Tell an object to listen to a particular event 
on another object. 
on - Bind a callback function to an object. 
stopListening - Tell an object to stop listening to 
events. 
Backbone events
Events on model 
Backbone events
Events on collection 
Backbone events
Events on View 
Backbone events
Trigger you own event 
Backbone events 
This way you can unbind the function 
to the object using “off"
Obrigado!

More Related Content

PPT
Meetup uikit programming
joaopmaia
 
PDF
Babushka
Richard McGain
 
PDF
Locarise,reagent and JavaScript Libraries
Ikuru Kanuma
 
PDF
Amplify your stack - Jsfoo pune 2012
threepointone
 
PDF
CoffeeScript in 5mins
Masakuni Kato
 
PDF
CoffeeScript Design Patterns
TrevorBurnham
 
PDF
Coffeescript: An Opinionated Introduction
Joe Fleming
 
Meetup uikit programming
joaopmaia
 
Babushka
Richard McGain
 
Locarise,reagent and JavaScript Libraries
Ikuru Kanuma
 
Amplify your stack - Jsfoo pune 2012
threepointone
 
CoffeeScript in 5mins
Masakuni Kato
 
CoffeeScript Design Patterns
TrevorBurnham
 
Coffeescript: An Opinionated Introduction
Joe Fleming
 

What's hot (19)

PDF
ECSをやろうとしました
晋也 古渡
 
PDF
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
PPTX
Java Stammtisch Würzburg - CONAIR
Matthias Reining
 
PPTX
Capistrano - automate all the things
John Cleary
 
PDF
Potential gotchas in making a backbone app
Vignesh Nandha Kumar
 
PPTX
Getting Started with Capistrano
LaunchAny
 
PDF
Using ArcGIS Server with Ruby on Rails
Dave Bouwman
 
PDF
Long Running PHP by Kamil Szymanski
The Business Transformation Network
 
PPT
Capistrano
Jason Noble
 
PDF
No Hugging, No Learning
Olaf Alders
 
PPTX
Ansible lightning talk at Scale 12
Justin Garrison
 
PDF
Unleashing the Rails Asset Pipeline
Kenneth Kalmer
 
PDF
Testing MeteorJS using CasperJS
Stephan Hochhaus
 
PPTX
Introducing Revel
Zhebr
 
KEY
CoffeeScript presentation
John Lynch
 
PDF
Sw install with_without_docker
SeongJae Park
 
PDF
Getting Started with Puppet on Windows - PuppetConf 2014
Puppet
 
PDF
CasperJs Enjoy Functional Testing
Fabien POMEROL
 
PDF
Build your website with awestruct and publish it on the cloud with git
Xavier Coulon
 
ECSをやろうとしました
晋也 古渡
 
HTML5 tutorial: canvas, offfline & sockets
Remy Sharp
 
Java Stammtisch Würzburg - CONAIR
Matthias Reining
 
Capistrano - automate all the things
John Cleary
 
Potential gotchas in making a backbone app
Vignesh Nandha Kumar
 
Getting Started with Capistrano
LaunchAny
 
Using ArcGIS Server with Ruby on Rails
Dave Bouwman
 
Long Running PHP by Kamil Szymanski
The Business Transformation Network
 
Capistrano
Jason Noble
 
No Hugging, No Learning
Olaf Alders
 
Ansible lightning talk at Scale 12
Justin Garrison
 
Unleashing the Rails Asset Pipeline
Kenneth Kalmer
 
Testing MeteorJS using CasperJS
Stephan Hochhaus
 
Introducing Revel
Zhebr
 
CoffeeScript presentation
John Lynch
 
Sw install with_without_docker
SeongJae Park
 
Getting Started with Puppet on Windows - PuppetConf 2014
Puppet
 
CasperJs Enjoy Functional Testing
Fabien POMEROL
 
Build your website with awestruct and publish it on the cloud with git
Xavier Coulon
 
Ad

Viewers also liked (9)

PPTX
CD Design process
sophjanecook
 
PDF
Chris Scott current credentials
Chris Scott
 
DOC
Осень зима меню ресторана Moma в центре Рима
ristorantemoma
 
PPTX
NEWSLETTER
Jeaneth Sagales
 
PPTX
Kalkınma Atölyesi - KALKINMAYA KATKI VERENLER PROGRAMI Tanıtım
Kalkınmaya Katkı Verenler
 
PPT
Kalkınmaya Katkı Verenler Yayın Setleri her yerde
Kalkınmaya Katkı Verenler
 
PDF
professional courses, awards, peoples and enterprises evaluations from 2000-2016
Ricardo Fonseca
 
PPT
The sandy hurricane- maria albea
marialbea
 
PDF
maintenance project
Mario Milošević
 
CD Design process
sophjanecook
 
Chris Scott current credentials
Chris Scott
 
Осень зима меню ресторана Moma в центре Рима
ristorantemoma
 
NEWSLETTER
Jeaneth Sagales
 
Kalkınma Atölyesi - KALKINMAYA KATKI VERENLER PROGRAMI Tanıtım
Kalkınmaya Katkı Verenler
 
Kalkınmaya Katkı Verenler Yayın Setleri her yerde
Kalkınmaya Katkı Verenler
 
professional courses, awards, peoples and enterprises evaluations from 2000-2016
Ricardo Fonseca
 
The sandy hurricane- maria albea
marialbea
 
maintenance project
Mario Milošević
 
Ad

Similar to Backbone the Good Parts (20)

PDF
[2015/2016] Backbone JS
Ivano Malavolta
 
PDF
Backbone JS for mobile apps
Ivano Malavolta
 
PDF
Backbone.js
Ivano Malavolta
 
PPT
Backbone.js
Knoldus Inc.
 
PDF
Developing maintainable Cordova applications
Ivano Malavolta
 
PDF
Backbone.js
Ivano Malavolta
 
PDF
Understanding backbonejs
Nick Lee
 
PDF
Backbone
Glenn De Backer
 
PPTX
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
PPTX
Backbonejs for beginners
Divakar Gu
 
PDF
Using Backbone.js with Drupal 7 and 8
Ovadiah Myrgorod
 
PPT
Backbone js-slides
DrupalCamp Kyiv Рысь
 
PPTX
Backbone.js
VO Tho
 
PPTX
Backbone
Sayed Ahmed
 
KEY
Give Your JavaScript Apps Some Spine
Lachlan Hardy
 
PDF
Viking academy backbone.js
Bert Wijnants
 
PPT
Backbone js
husnara mohammad
 
PDF
Developing Backbonejs Applications Early Release Addy Osmani
littelenkali
 
PDF
Intro to BackboneJS + Intermediate Javascript
Andrew Lovett-Barron
 
PDF
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 
[2015/2016] Backbone JS
Ivano Malavolta
 
Backbone JS for mobile apps
Ivano Malavolta
 
Backbone.js
Ivano Malavolta
 
Backbone.js
Knoldus Inc.
 
Developing maintainable Cordova applications
Ivano Malavolta
 
Backbone.js
Ivano Malavolta
 
Understanding backbonejs
Nick Lee
 
Backbone
Glenn De Backer
 
BackboneJS Training - Giving Backbone to your applications
Joseph Khan
 
Backbonejs for beginners
Divakar Gu
 
Using Backbone.js with Drupal 7 and 8
Ovadiah Myrgorod
 
Backbone js-slides
DrupalCamp Kyiv Рысь
 
Backbone.js
VO Tho
 
Backbone
Sayed Ahmed
 
Give Your JavaScript Apps Some Spine
Lachlan Hardy
 
Viking academy backbone.js
Bert Wijnants
 
Backbone js
husnara mohammad
 
Developing Backbonejs Applications Early Release Addy Osmani
littelenkali
 
Intro to BackboneJS + Intermediate Javascript
Andrew Lovett-Barron
 
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 

Recently uploaded (20)

PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Exploring AI Agents in Process Industries
amoreira6
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 

Backbone the Good Parts

  • 2. Renan Carvalho Carioca U2 fan Frustrated musician Beer Appreciator King of age of empires Love agile methods Front end developer at Chute Blog : rcarvalhojs.com Github : renancarvalho Twitter : rcarvalhojs Hate who says bad things about JS
  • 3. The examples will be based on blogMv project https://github.com/blogmv/backbone-browserify More info http://blogmv.github.io
  • 4. What’s the problem? What’s backbone? Keep data synchronized Complex code Spaghetti code Manage callbacks Ajax, XHR? (Impossible to remember the syntax) How to test it? :( - TDD? http://www.tddunlocked.com.br/
  • 5. “Backbone is a mindset change.” Renan Carvalho What’s backbone?
  • 6. And it’s also… Javascript library Based on MV* concept Lightweight (production version has 6.5kb) Depends on underscore Trust me, it’s awesome! What’s backbone?
  • 7. What are you building?
  • 10. For complex users interface Reusable code Build single page apps When you don’t know what kind of “helicopter” When to use? When to use it? Complex systems Good Integration with legacy code Simple systems Really performatic system If you’re under 18 (Flying lollipop)
  • 11. Router Url routing using (#home or /home) Application history
  • 13. Backbone.history.start(), to start to track url (hashChanges) If you’d like to use html5 push state, just use Backbone.history.start({pushState: true}) Backbone router More examples : http://backbonejs.org/#Router
  • 14. View Represents models data Handle user interaction (input events)
  • 15. View render() - Convenction function for render view. Be careful with SRP el - Dom object, that will be used as the view reference (default is a <div>) $el - Jquery object that keeps the reference to el. initialize() - “Constructor” function for every backbone class events - Handle view events like ( click, change…) Backbone view
  • 18. Example of bad implementation Backbone view
  • 19. Example of good implementation Backbone view
  • 20. Model Manage data. Validate data know where to send/get data Should be thin and beautiful
  • 21. Model fetch() - get data from server save() - post/put data on server If the model has an id attribute, backbone will perform a put. get/set - get/set attributes on model parse - function called before backbone merge the server content with the model. validate - perform custom validations on model. Fired when save(), set or invoked. url - server endpoint (api), where model will perform the request More about backbone models: http://backbonejs.org/#Model Backbone model
  • 22. Example of bad implementation Backbone model
  • 24. Collection Basically “a lot of models together"
  • 25. Collection fetch() - Exactly like model, get data from server. create() - Create a new model instance within a collection (save on server). push() - add a model at the end of the collection add - add a model into a collection, you can specify the position where the model will be added ( this.collection.add(new model(), {at : 8}); ) reset() - sets the collection with an array of models. More about backbone collection: http://backbonejs.org/#Collection Backbone collection
  • 28. Catalog of Events Backbone events
  • 29. listenTo - Tell an object to listen to a particular event on another object. on - Bind a callback function to an object. stopListening - Tell an object to stop listening to events. Backbone events
  • 30. Events on model Backbone events
  • 31. Events on collection Backbone events
  • 32. Events on View Backbone events
  • 33. Trigger you own event Backbone events This way you can unbind the function to the object using “off"