SlideShare a Scribd company logo
1 of 24
Download to read offline
Potential gotchas in making a
Backbone app
JSFoo 2013 - Sep 20, 21
Me
Vignesh Nandha Kumar
Making Crafting UX for Recruiterbox
Why use Backbone?
➔ robust
➔ tiny
➔ mature
➔ community (plugins & extensions)
➔ There is no magic
There is no magic
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
There is no magic
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
var AnyModelView = Backbone.View.extend({
initialize: function() {
this.model.on('change', this.render, this);
this.model.on('destroy', this.remove, this);
},
render: function() {
var template =_.template(
$('#jst-some-template').html()
);
this.$el.html(template(this.model.toJSON()));
return this;
}
});
Boilerplate
var AnyCollectionView = Backbone.View.extend({
initialize: function() {
this.collection.on('add', this.appendItem, this);
},
render: function() {
this.$el.empty();
this.collection.each(this.appendItem, this);
return this;
},
appendItem: function( model ) {
this.$el.append(new AnyModelView({
model: model
}).render().$el);
}
});
Boilerplate [contd]
There is no magic
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
Zombies
“Whenever I visit the same page more than once,
I see one more copy of the view getting created every time?”
or
“How do I make sure I clean things up when moving to a new
page in my app?”
https://gist.github.com/vikynandha/6540811
https://github.com/vikynandha/BackboneZombieDemo
There is no magic
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
Duplicate copies
var Article = Backbone.Model.extend({
parse: function( resp ) {
return _(resp).extend({
author: new User(resp.author)
});
}
});
var post1 = new Article(),
post2 = new Article();
post1.get('author').id === post2.get('author').id; // true
post1.get('author') === post2.get('author'); // false
Duplicate copies
var Article = Backbone.Model.extend({
parse: function( resp ) {
return _(resp).extend({
author: new User(resp.author)
});
}
});
var post1 = new Article(),
post2 = new Article();
post1.get('author').id === post2.get('author').id; // true
post1.get('author') === post2.get('author'); // false
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
There is no magic
➔ doesn’t tell you best practices
➔ too much boilerplate
➔ leads to zombies
➔ duplicate copies of data
➔ end up in mess if you don’t plan well
There is no magic
Solution?
Solution?
So many plugins available out there
https://github.com/jashkenas/backbone/wiki/Extensions,-Plugins,-Resources
Boilerplate gone!
var MyModelView = Backbone.Marionette.ItemView.extend({
template: '#jst-some-template',
modelEvents: {
'change': 'render',
'destroy': 'remove'
}
});
Zombies killed!
Built-in memory management and zombie killing
Regions & Layouts
Managing nested sub-views is a piece of cake
Marionette
➔ Composite Application Framework
"The secret to building large apps is never build large apps.
Break your applications into small pieces. Then, assemble
those testable, bite-sized pieces into your big application"
-Justin Meyer, author JavaScriptMVC
Thank you!
https://github.com/vikynandha/
https://github.com/aplopio/
References
1. http://backbonejs.org
2. http://lostechies.
com/derickbailey/2011/09/15/zombies-run-
managing-page-transitions-in-backbone-apps/
3. http://marionettejs.com
4. http://amy.palamounta.in/2013/04/12/unsuck-
your-backbone/

More Related Content

What's hot

Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
FDConf
 
JavaScript Sprachraum
JavaScript SprachraumJavaScript Sprachraum
JavaScript Sprachraum
patricklee
 
Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScript
WebF
 

What's hot (20)

Virthualenvwrapper
VirthualenvwrapperVirthualenvwrapper
Virthualenvwrapper
 
站在angular的視角回頭看backbone - Data與Event
站在angular的視角回頭看backbone - Data與Event站在angular的視角回頭看backbone - Data與Event
站在angular的視角回頭看backbone - Data與Event
 
Будь первым
Будь первымБудь первым
Будь первым
 
Star bed 2018.07.19
Star bed 2018.07.19Star bed 2018.07.19
Star bed 2018.07.19
 
Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014Wrangling WP_Cron - WordCamp Grand Rapids 2014
Wrangling WP_Cron - WordCamp Grand Rapids 2014
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
 
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
 
非同期javascriptの過去と未来
非同期javascriptの過去と未来非同期javascriptの過去と未来
非同期javascriptの過去と未来
 
Async programming on NET
Async programming on NETAsync programming on NET
Async programming on NET
 
Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパー
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
I love Automation
I love AutomationI love Automation
I love Automation
 
JavaScript Sprachraum
JavaScript SprachraumJavaScript Sprachraum
JavaScript Sprachraum
 
Asynchronous Programming with JavaScript
Asynchronous Programming with JavaScriptAsynchronous Programming with JavaScript
Asynchronous Programming with JavaScript
 
G*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョンG*なクラウド 雲のかなたに ショートバージョン
G*なクラウド 雲のかなたに ショートバージョン
 
Introduction to underscore.js
Introduction to underscore.jsIntroduction to underscore.js
Introduction to underscore.js
 
Backbonejs on Rails
Backbonejs on RailsBackbonejs on Rails
Backbonejs on Rails
 
تذكرة الصيام
تذكرة الصيامتذكرة الصيام
تذكرة الصيام
 
Google App Engine Developer - Day4
Google App Engine Developer - Day4Google App Engine Developer - Day4
Google App Engine Developer - Day4
 

Viewers also liked (6)

Ua-Tenders Promo
Ua-Tenders PromoUa-Tenders Promo
Ua-Tenders Promo
 
Using animation to bring biology to life
Using animation to bring biology to lifeUsing animation to bring biology to life
Using animation to bring biology to life
 
10 minute presentation 1
10 minute presentation 110 minute presentation 1
10 minute presentation 1
 
Ric technology, teaching and learning
Ric   technology, teaching and learningRic   technology, teaching and learning
Ric technology, teaching and learning
 
Using animation to bring biology to life
Using animation to bring biology to lifeUsing animation to bring biology to life
Using animation to bring biology to life
 
Hulshoff veranderen is bewegen sessie 1
Hulshoff veranderen is bewegen sessie 1Hulshoff veranderen is bewegen sessie 1
Hulshoff veranderen is bewegen sessie 1
 

Similar to Potential gotchas in making a backbone app

前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
archwisp
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 

Similar to Potential gotchas in making a backbone app (20)

Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Simple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with PerlSimple Photo Processing and Web Display with Perl
Simple Photo Processing and Web Display with Perl
 
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
 
node.js Module Development
node.js Module Developmentnode.js Module Development
node.js Module Development
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QACreating "Secure" PHP Applications, Part 1, Explicit Code & QA
Creating "Secure" PHP Applications, Part 1, Explicit Code & QA
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Future of Web Apps: Google Gears
Future of Web Apps: Google GearsFuture of Web Apps: Google Gears
Future of Web Apps: Google Gears
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Potential gotchas in making a backbone app

  • 1. Potential gotchas in making a Backbone app JSFoo 2013 - Sep 20, 21
  • 2. Me Vignesh Nandha Kumar Making Crafting UX for Recruiterbox
  • 3. Why use Backbone? ➔ robust ➔ tiny ➔ mature ➔ community (plugins & extensions) ➔ There is no magic
  • 4.
  • 5. There is no magic ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well
  • 6. There is no magic ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well
  • 7. var AnyModelView = Backbone.View.extend({ initialize: function() { this.model.on('change', this.render, this); this.model.on('destroy', this.remove, this); }, render: function() { var template =_.template( $('#jst-some-template').html() ); this.$el.html(template(this.model.toJSON())); return this; } }); Boilerplate
  • 8. var AnyCollectionView = Backbone.View.extend({ initialize: function() { this.collection.on('add', this.appendItem, this); }, render: function() { this.$el.empty(); this.collection.each(this.appendItem, this); return this; }, appendItem: function( model ) { this.$el.append(new AnyModelView({ model: model }).render().$el); } }); Boilerplate [contd]
  • 9. There is no magic ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well
  • 10. Zombies “Whenever I visit the same page more than once, I see one more copy of the view getting created every time?” or “How do I make sure I clean things up when moving to a new page in my app?” https://gist.github.com/vikynandha/6540811 https://github.com/vikynandha/BackboneZombieDemo
  • 11. There is no magic ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well
  • 12. Duplicate copies var Article = Backbone.Model.extend({ parse: function( resp ) { return _(resp).extend({ author: new User(resp.author) }); } }); var post1 = new Article(), post2 = new Article(); post1.get('author').id === post2.get('author').id; // true post1.get('author') === post2.get('author'); // false
  • 13. Duplicate copies var Article = Backbone.Model.extend({ parse: function( resp ) { return _(resp).extend({ author: new User(resp.author) }); } }); var post1 = new Article(), post2 = new Article(); post1.get('author').id === post2.get('author').id; // true post1.get('author') === post2.get('author'); // false
  • 14. ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well There is no magic
  • 15. ➔ doesn’t tell you best practices ➔ too much boilerplate ➔ leads to zombies ➔ duplicate copies of data ➔ end up in mess if you don’t plan well There is no magic
  • 17. Solution? So many plugins available out there https://github.com/jashkenas/backbone/wiki/Extensions,-Plugins,-Resources
  • 18.
  • 19. Boilerplate gone! var MyModelView = Backbone.Marionette.ItemView.extend({ template: '#jst-some-template', modelEvents: { 'change': 'render', 'destroy': 'remove' } });
  • 20. Zombies killed! Built-in memory management and zombie killing
  • 21. Regions & Layouts Managing nested sub-views is a piece of cake
  • 22. Marionette ➔ Composite Application Framework "The secret to building large apps is never build large apps. Break your applications into small pieces. Then, assemble those testable, bite-sized pieces into your big application" -Justin Meyer, author JavaScriptMVC