SlideShare a Scribd company logo
1 of 20
BACKBONE.JS
Giving backbone to your applications
About Me
Joseph Khan
SMTS, Yodlee
Author, ISBN – 9781849694001
Open Source
@joseph_rialab
Roadmap
Total Time: 3 hours
1. What is MVC?
2. What are SPA’s?
3. Discuss about developing web applications, separation of concerns, traditional way
of developing and how Backbone gives structure
4. Backbone dependencies – jQuery, Underscore
5. Setup needed to code – local server, libraries, editor
6. Backbone Core Components
Model
Views
Collections
Controllers?
Events
Routers
7. Live Demo App – Employee Manager Single Page Application
8. Questions and Quiz
9. References – links and books
Tools needed
What do I need to code?
1. Local HTTP server – WAMP/MAMP
2. Text/Code editor – I prefer Sublime Text
3. JS libraries
1. Backbone.js
2. jQuery.js
3. Underscore.js
4. Some patience
What is MVC Pattern?
What is a Single Page Application?
Once the application loads, majority of the functionality is handled client side only.
Calls are made to the server for data feeds.
Eg. Gmail, Our Demo App
What is Backbone.JS?
Backbone.JS dependencies
• jQuery – DOM manipulations
• Underscore JS – Utility functions
Backbone Components
Backbone – a global object
• Model
• Collection
• View
• Events
• Router
Models
Model data for a real world entity. Its like a database row. They contain data for an
application as well as the logic around the data.
Eg. Todo Item, an Employee
var EmployeeModel = Backbone.Model.extend({});
var employeeModel = new EmployeeModel();
• Initialization
• Setting default values
• Getters and Setters
• Data Validation
• Handling change events
• Some other very useful model properties – toJSON(), attributes, save()
Collections
Group or set of models. Its like the database table
Eg. Todo List, Employee List
var EmployeeCollection = Backbone.Collection.extend({
url: “…”,
model: EmployeeModel,
initialize: function() {
},
parse: function(response) {
}
});
var employees = new EmployeeCollection();
• Creating a collection class
• url property
• model property
• parse() method
• Creating a collection instance
• Adding and removing models
• Add, remove, reset events
• fetch() method
• Other useful properties – get(),
forEach()
Templates (basics)
• Makes life easier. Converts user data into HTML markup
• We will use Underscore templates _.template()
<script type="text/template" id="todoTemplate">
<p class='todo-title'><%= title %></p>
<p><%= completed %></p>
</script>
JSON data/Model Data
HTML markup
{
title: ‘Get Eggs’,
completed: false
}
<p class='todo-title’>Get Eggs</p>
<p>false</p>
Views
• Views in Backbone don’t contain the HTML markup for your application; they contain the
• logic behind the presentation of the model’s data to the user.
• They use templates to do so
var EmployeeView = Backbone.View.extend({
tagName: 'li',
className: 'employeeItem row’,
events: {
'click #removeBtn' : 'removeEmployee'
},
initialize: function() {
console.log("Employee View initialized");
},
render: function() {
},
removeEmployee: function() {
}
});
var employee1 = new EmployeeView();
• Creating a View class
• Associating views with DOM elements –
el, tagName
• initialize() method
• render() method
• Events hash map – DOM events
• Listening to model changes
• Creating a view object
• Passing model to a view
• Converting model data into HTML markup
• el, $el properties
Events
Two ways to handle events
• DOM level events – hashmap
• Object level events – one object listening to another object
var EmployeeView = Backbone.View.extend({
tagName: 'li',
className: 'employeeItem row’,
events: {
'click #removeBtn' : 'removeEmployee'
},
initialize: function() {
this.listenTo(this.model, ‘change’,
someFunc)
},
removeEmployee: function() {
}
});
var employee1 = new EmployeeView();
• on()
• off()
• trigger()
• listenTo()
• stopListening()
• events: {} object
Code Live
Let’s create an Employee Manager Application
Demo Application Structure
Adding a new employee
Removing an employee
Demo Application Structure
Edit
Folder Structure
Books and Links
Official Site - http://backbonejs.org/
Tutorial - https://backbonetutorials.com/
Free ebook - http://addyosmani.github.io/backbone-fundamentals/
Backbone Todo App - http://todomvc.com/examples/backbone/
Developing Backbone.js Applications by
Addy Osmani
Thanks
Q/A

More Related Content

What's hot

Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developers
AoteaStudios
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
NCCOMMS
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 

What's hot (19)

Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
 
Rails course day 7
Rails course day 7Rails course day 7
Rails course day 7
 
Intro to emberjs
Intro to emberjsIntro to emberjs
Intro to emberjs
 
Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developers
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
In-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascriptIn-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascript
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 
Backbone/Marionette introduction
Backbone/Marionette introductionBackbone/Marionette introduction
Backbone/Marionette introduction
 
BackboneJS + ReactJS
BackboneJS + ReactJSBackboneJS + ReactJS
BackboneJS + ReactJS
 
Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8Upgrade your javascript to drupal 8
Upgrade your javascript to drupal 8
 
Effective cassandra development with achilles
Effective cassandra development with achillesEffective cassandra development with achilles
Effective cassandra development with achilles
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 

Similar to BackboneJS Training - Giving Backbone to your applications

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 

Similar to BackboneJS Training - Giving Backbone to your applications (20)

Approaches to mobile site development
Approaches to mobile site developmentApproaches to mobile site development
Approaches to mobile site development
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Story ofcorespring infodeck
Story ofcorespring infodeckStory ofcorespring infodeck
Story ofcorespring infodeck
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
 
CCCDjango2010.pdf
CCCDjango2010.pdfCCCDjango2010.pdf
CCCDjango2010.pdf
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application dance
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

BackboneJS Training - Giving Backbone to your applications

  • 1. BACKBONE.JS Giving backbone to your applications
  • 2. About Me Joseph Khan SMTS, Yodlee Author, ISBN – 9781849694001 Open Source @joseph_rialab
  • 3. Roadmap Total Time: 3 hours 1. What is MVC? 2. What are SPA’s? 3. Discuss about developing web applications, separation of concerns, traditional way of developing and how Backbone gives structure 4. Backbone dependencies – jQuery, Underscore 5. Setup needed to code – local server, libraries, editor 6. Backbone Core Components Model Views Collections Controllers? Events Routers 7. Live Demo App – Employee Manager Single Page Application 8. Questions and Quiz 9. References – links and books
  • 4. Tools needed What do I need to code? 1. Local HTTP server – WAMP/MAMP 2. Text/Code editor – I prefer Sublime Text 3. JS libraries 1. Backbone.js 2. jQuery.js 3. Underscore.js 4. Some patience
  • 5. What is MVC Pattern?
  • 6. What is a Single Page Application? Once the application loads, majority of the functionality is handled client side only. Calls are made to the server for data feeds. Eg. Gmail, Our Demo App
  • 8. Backbone.JS dependencies • jQuery – DOM manipulations • Underscore JS – Utility functions
  • 9. Backbone Components Backbone – a global object • Model • Collection • View • Events • Router
  • 10. Models Model data for a real world entity. Its like a database row. They contain data for an application as well as the logic around the data. Eg. Todo Item, an Employee var EmployeeModel = Backbone.Model.extend({}); var employeeModel = new EmployeeModel(); • Initialization • Setting default values • Getters and Setters • Data Validation • Handling change events • Some other very useful model properties – toJSON(), attributes, save()
  • 11. Collections Group or set of models. Its like the database table Eg. Todo List, Employee List var EmployeeCollection = Backbone.Collection.extend({ url: “…”, model: EmployeeModel, initialize: function() { }, parse: function(response) { } }); var employees = new EmployeeCollection(); • Creating a collection class • url property • model property • parse() method • Creating a collection instance • Adding and removing models • Add, remove, reset events • fetch() method • Other useful properties – get(), forEach()
  • 12. Templates (basics) • Makes life easier. Converts user data into HTML markup • We will use Underscore templates _.template() <script type="text/template" id="todoTemplate"> <p class='todo-title'><%= title %></p> <p><%= completed %></p> </script> JSON data/Model Data HTML markup { title: ‘Get Eggs’, completed: false } <p class='todo-title’>Get Eggs</p> <p>false</p>
  • 13. Views • Views in Backbone don’t contain the HTML markup for your application; they contain the • logic behind the presentation of the model’s data to the user. • They use templates to do so var EmployeeView = Backbone.View.extend({ tagName: 'li', className: 'employeeItem row’, events: { 'click #removeBtn' : 'removeEmployee' }, initialize: function() { console.log("Employee View initialized"); }, render: function() { }, removeEmployee: function() { } }); var employee1 = new EmployeeView(); • Creating a View class • Associating views with DOM elements – el, tagName • initialize() method • render() method • Events hash map – DOM events • Listening to model changes • Creating a view object • Passing model to a view • Converting model data into HTML markup • el, $el properties
  • 14. Events Two ways to handle events • DOM level events – hashmap • Object level events – one object listening to another object var EmployeeView = Backbone.View.extend({ tagName: 'li', className: 'employeeItem row’, events: { 'click #removeBtn' : 'removeEmployee' }, initialize: function() { this.listenTo(this.model, ‘change’, someFunc) }, removeEmployee: function() { } }); var employee1 = new EmployeeView(); • on() • off() • trigger() • listenTo() • stopListening() • events: {} object
  • 15. Code Live Let’s create an Employee Manager Application
  • 16. Demo Application Structure Adding a new employee Removing an employee
  • 19. Books and Links Official Site - http://backbonejs.org/ Tutorial - https://backbonetutorials.com/ Free ebook - http://addyosmani.github.io/backbone-fundamentals/ Backbone Todo App - http://todomvc.com/examples/backbone/ Developing Backbone.js Applications by Addy Osmani