SlideShare uma empresa Scribd logo
1 de 31
INTRODUCTION
    THO VO
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
INTRODUCTION

• JavaScript found in 1995(stable 1.8.5 in 2011).
• JavaScript frameworks:
  •   MochiKit(2008).
  •   Rico(2009).
  •   YUI(2011).
  •   Ext JS(2011).
  •   Dojo(2011).
  •   Echo3(2011).
  •   jQuery(2012).
  •   …and other frameworks here.
COMPARISON

                 jQuery        Ext JS     YUI
Files            1             1          1
.js (LOC)        9047          13471      10526


   •    Is it easy to read?
   •    Is it easy to upgrade?
   •    How can I add a new feature?
   •    Does these library support OOP?
   •    3 layers?
   •    MVC?
   •  ‘spaghetti         ’ code
COMPARISON( CONT. )

• jQuery, Ext JS, YUI…write code focus on functions,
  these library provides api and the users use these
  functions to achieve what they want.
  • YUI API.
  • jQuery API.
  • Ext JS API.
WHY USE THIS?

• A MVC like pattern to keep code clean.
• A templating language to easily render view
  element.
• A better way to manage events and callbacks.
• A way to preserver back button.
• Easy for testing.
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
MVC AND OTHER MODELS IN
            JAVASCRIPT.


•   MV*
•   MVC
•   MVP
•   MVVM
•   …
FRAMEWORKS

•   Backbone.js
•   Sprout Core 1.x
•   Sammy.js
•   Spine.js
•   Cappuccino
•   Knockout.js
•   JavaScript MVC
•   Google Web Toolkit
•   Batman.js
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
THIRD PARTY LIBRARY FOR BACKBONE.

• Selector:
  • jQuery
  • YUI
  • Zepto
• Template:
  •   Underscore(hard dependency)
  •   Handlebar
  •   Tempo
  •   Mustache
ARCHITECT OF A BACKBONE PROJECT

• Assets: CSS, images, third party JavaScript library…
• Modules: Our source, view.js, model.js
• Have more directories when project come
  larger…
HTML
1.    <!doctype html>
2.    <html lang="en">
3.    <head>
4.        <meta charset="utf-8">
5.        <meta http-equiv="X-UA-Comptatible" content="IE=edge,chrome=1">
6.        <title>Backbone.js</title>
7.        <link rel="stylesheet" href="assets/css/main.css">
8.    </head>
9.    <body>
10.       <div id="content">
11.       <!-- Content goes here -->
12.       </div>
13.       <!-- Libraries, follow this order -->
14.       <script type="text/javascript" src="assets/js/libs/jquery.min.js"></script>
15.       <script type="text/javascript" src="assets/js/libs/underscore-min.js"></script>
16.       <script type="text/javascript" src="assets/js/libs/backbone-min.js"></script>
17.       <!-- Application JavaScript -->
18.       <script type="text/javascript" src="src/app.js"></script>
19.   </body>
20.   </html>
NAMESPACE
1.    var app = {
2.        // Classes
3.        Collections: {},
4.        Models: {},
5.        Views: {},
6.        // Instances
7.        collections: {},
8.        models: {},
9.        views: {},
10.       init: function () {
11.           // Constructor
12.       }
13.   };
14.   $(document).ready(function () {
15.       // Run on the first time the document has been loaded
16.       app.init();
17.   });
MODULES

• src/modules/views.js :
1. app.Views.main = Backbone.View.extend({
2.     initialize: function () {
3.         // View init
4.         console.log('Main view initialized !');
5.     }
6. });
• Add view in app.js
• src/app.js :
1. init: function () {
2.     // Init
3.     this.views.main = new this.Views.main();
4. }
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
MODEL

• Manage data(CVDP).
• Change the data of a model  notify changes to
  view
1. var Photo = Backbone.Model.extend({
2.      // Default attributes for the photo
3.      defaults: {
4.          src: "placeholder.jpg",
5.          caption: "A default image",
6.          viewed: false
7.      },
8.      // Ensure that each photo created has an `src`.
9.      initialize: function () {
10.         this.set({ "src": this.defaults.src });
11.     }
12. });
MODEL(CONT.)

•   Validation data.
•   Persistence data on server.
•   Allow multiple views on a model.
•   …
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
COLLECTION

•   Group models .
•   Trigger events like add/remove/refresh.
•   Can fetch models from a given URL.
•   Can keep the model sorted.
•   Write application logic based on notifications from
    the group should any model it contains be
    changed.
    needn’t to watch every individual model instance.
COLLECTION(CONT.)

1.var PhotoGallery = Backbone.Collection.extend({
2.     // Reference to this collection's model.
3.     model: Photo,
4.     // Filter down the list of all photos
5.     // that have been viewed
6.     viewed: function() {
7.         return this.filter(function(photo){
8.            return photo.get('viewed');
9.         });
10.     },
11.     // Filter down the list to only photos that
12.     // have not yet been viewed
13.     unviewed: function() {
14.       return this.without.apply(this, this.viewed());
15.     }
16.});
PLAN

1.   Introduction.
2.   MVC and other models in JavaScript.
3.   Third party library for Backbone.
4.   Model with Backbone.
5.   Collection with Backbone.
6.   View with Backbone.
7.   Demo.
8.   Question and Answer?
VIEW

• Visual representation of models .
• Observes a model and is notified when the model
  changes  update accordingly.
• View in Backbone isn’t a CONTROLLER , it just can
  add an event listener to delegate handling the
  behavior to the controller.
1.var buildPhotoView = function( photoModel, photoController ){
2.    var base         = document.createElement('div'),
3.         photoEl     = document.createElement('div');
4.     base.appendChild(photoEl);
5.     var render= function(){
6.         // We use a templating library such as Underscore
7.         // templating which generates the HTML for our photo entry
8.        photoEl.innerHTML = _.template('photoTemplate', {src: photoModel.getSrc()});
9.     }
10.     photoModel.addSubscriber( render );
11.     photoEl.addEventListener('click', function(){
12.         photoController.handleEvent('click', photoModel );
13.     });
14.     var show = function(){
15.         photoEl.style.display = '';
16.     }
17.     var hide = function(){
18.         photoEl.style.display = 'none';
19.     }
20.     return{
21.         showView: show,
22.         hideView: hide
23.     }
24.}
CONTROLLER

• Backbone didn’t actually provide a Controller.
• In Backbone, View and Router does a little similar to
  a Controller.
• Router binds the event for a Model and have View
  for respond to this event.
1.   var PhotoRouter = Backbone.Router.extend({
2.     routes: { "photos/:id": "route" },
3.     route: function(id) {
4.       var item = photoCollection.get(id);
5.       var view = new PhotoView({ model: item });
6.       something.html( view.render().el );
7.     }
8.   }):
BENEFITS OF MVC

1. Easier overall maintenance.
2. Decoupling models and views  easy to write unit
   test and business logic.
3. Duplication of low-level model and controller
   code is eliminated across the application.
4. Work simultaneously between core logic and user
   interface.
NOTES

• Core components: Model, View, Collection, Router.
• Complete documentation.
• Used by large companies such as SoundCloud and
  Foursquare.
• Event-driven communication.
• No default templating engine.
• Clear and flexible conventions for structuring
  applications.
• …
PLUGIN

• Deeply nested models:
  • Backbone Relational
  • Ligament
• Store data:
  • Backbone localStorage
  • Small Backbone ORM
• View:
  • LayoutManager
  • Backbone.Marionette
• More at here.
DEMO

• Other demo can view here:
 •   Todos
 •   Backbone Google Book
 •   Todos of Niquet
 •   …
QUESTION AND ANSWER
THANK YOU FOR YOUR ATTENTIONS




             !

Mais conteúdo relacionado

Mais procurados

Requirejs
RequirejsRequirejs
Requirejssioked
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack IntroductionAnjali Chawla
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSEmil Öberg
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJsTudor Barbu
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications Juliana Lucena
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCVisual Engineering
 
The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014Matt Raible
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSDen Odell
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJohan Nilsson
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPressCaldera Labs
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slidesmattysmith
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Deutsche Post
 
Angular js vs. Facebook react
Angular js vs. Facebook reactAngular js vs. Facebook react
Angular js vs. Facebook reactKeyup
 

Mais procurados (20)

Webpack
WebpackWebpack
Webpack
 
Requirejs
RequirejsRequirejs
Requirejs
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
An Intro into webpack
An Intro into webpackAn Intro into webpack
An Intro into webpack
 
Webpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JSWebpack Tutorial, Uppsala JS
Webpack Tutorial, Uppsala JS
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Workshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVCWorkshop 9: BackboneJS y patrones MVC
Workshop 9: BackboneJS y patrones MVC
 
The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014The Art of AngularJS - DeRailed 2014
The Art of AngularJS - DeRailed 2014
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Requirejs
RequirejsRequirejs
Requirejs
 
Webpack DevTalk
Webpack DevTalkWebpack DevTalk
Webpack DevTalk
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
JavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & BrowserifyJavaScript Dependencies, Modules & Browserify
JavaScript Dependencies, Modules & Browserify
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
 
webpack 101 slides
webpack 101 slideswebpack 101 slides
webpack 101 slides
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
 
Angular js vs. Facebook react
Angular js vs. Facebook reactAngular js vs. Facebook react
Angular js vs. Facebook react
 

Semelhante a Backbone.js

jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applicationsDivyanshGupta922023
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsJoseph Khan
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSébastien Levert
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile appsIvano Malavolta
 
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
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Doris Chen
 
Introduction to design_patterns
Introduction to design_patternsIntroduction to design_patterns
Introduction to design_patternsamitarcade
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!Roberto Messora
 
Plone FSR
Plone FSRPlone FSR
Plone FSRfulv
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endSaeid Zebardast
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpChalermpon Areepong
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer ToolsWO Community
 

Semelhante a Backbone.js (20)

jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
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...
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
Introduction to design_patterns
Introduction to design_patternsIntroduction to design_patterns
Introduction to design_patterns
 
MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!MV* presentation frameworks in Javascript: en garde, pret, allez!
MV* presentation frameworks in Javascript: en garde, pret, allez!
 
Plone FSR
Plone FSRPlone FSR
Plone FSR
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
 
Readme
ReadmeReadme
Readme
 
Angular js
Angular jsAngular js
Angular js
 
Angular js
Angular jsAngular js
Angular js
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
WebObjects Developer Tools
WebObjects Developer ToolsWebObjects Developer Tools
WebObjects Developer Tools
 

Último

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 

Último (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Backbone.js

  • 1. INTRODUCTION THO VO
  • 2. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 3. INTRODUCTION • JavaScript found in 1995(stable 1.8.5 in 2011). • JavaScript frameworks: • MochiKit(2008). • Rico(2009). • YUI(2011). • Ext JS(2011). • Dojo(2011). • Echo3(2011). • jQuery(2012). • …and other frameworks here.
  • 4. COMPARISON jQuery Ext JS YUI Files 1 1 1 .js (LOC) 9047 13471 10526 • Is it easy to read? • Is it easy to upgrade? • How can I add a new feature? • Does these library support OOP? • 3 layers? • MVC? •  ‘spaghetti ’ code
  • 5. COMPARISON( CONT. ) • jQuery, Ext JS, YUI…write code focus on functions, these library provides api and the users use these functions to achieve what they want. • YUI API. • jQuery API. • Ext JS API.
  • 6. WHY USE THIS? • A MVC like pattern to keep code clean. • A templating language to easily render view element. • A better way to manage events and callbacks. • A way to preserver back button. • Easy for testing.
  • 7. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 8. MVC AND OTHER MODELS IN JAVASCRIPT. • MV* • MVC • MVP • MVVM • …
  • 9. FRAMEWORKS • Backbone.js • Sprout Core 1.x • Sammy.js • Spine.js • Cappuccino • Knockout.js • JavaScript MVC • Google Web Toolkit • Batman.js
  • 10. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 11. THIRD PARTY LIBRARY FOR BACKBONE. • Selector: • jQuery • YUI • Zepto • Template: • Underscore(hard dependency) • Handlebar • Tempo • Mustache
  • 12. ARCHITECT OF A BACKBONE PROJECT • Assets: CSS, images, third party JavaScript library… • Modules: Our source, view.js, model.js • Have more directories when project come larger…
  • 13. HTML 1. <!doctype html> 2. <html lang="en"> 3. <head> 4. <meta charset="utf-8"> 5. <meta http-equiv="X-UA-Comptatible" content="IE=edge,chrome=1"> 6. <title>Backbone.js</title> 7. <link rel="stylesheet" href="assets/css/main.css"> 8. </head> 9. <body> 10. <div id="content"> 11. <!-- Content goes here --> 12. </div> 13. <!-- Libraries, follow this order --> 14. <script type="text/javascript" src="assets/js/libs/jquery.min.js"></script> 15. <script type="text/javascript" src="assets/js/libs/underscore-min.js"></script> 16. <script type="text/javascript" src="assets/js/libs/backbone-min.js"></script> 17. <!-- Application JavaScript --> 18. <script type="text/javascript" src="src/app.js"></script> 19. </body> 20. </html>
  • 14. NAMESPACE 1. var app = { 2. // Classes 3. Collections: {}, 4. Models: {}, 5. Views: {}, 6. // Instances 7. collections: {}, 8. models: {}, 9. views: {}, 10. init: function () { 11. // Constructor 12. } 13. }; 14. $(document).ready(function () { 15. // Run on the first time the document has been loaded 16. app.init(); 17. });
  • 15. MODULES • src/modules/views.js : 1. app.Views.main = Backbone.View.extend({ 2. initialize: function () { 3. // View init 4. console.log('Main view initialized !'); 5. } 6. }); • Add view in app.js • src/app.js : 1. init: function () { 2. // Init 3. this.views.main = new this.Views.main(); 4. }
  • 16. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 17. MODEL • Manage data(CVDP). • Change the data of a model  notify changes to view 1. var Photo = Backbone.Model.extend({ 2. // Default attributes for the photo 3. defaults: { 4. src: "placeholder.jpg", 5. caption: "A default image", 6. viewed: false 7. }, 8. // Ensure that each photo created has an `src`. 9. initialize: function () { 10. this.set({ "src": this.defaults.src }); 11. } 12. });
  • 18. MODEL(CONT.) • Validation data. • Persistence data on server. • Allow multiple views on a model. • …
  • 19. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 20. COLLECTION • Group models . • Trigger events like add/remove/refresh. • Can fetch models from a given URL. • Can keep the model sorted. • Write application logic based on notifications from the group should any model it contains be changed. needn’t to watch every individual model instance.
  • 21. COLLECTION(CONT.) 1.var PhotoGallery = Backbone.Collection.extend({ 2. // Reference to this collection's model. 3. model: Photo, 4. // Filter down the list of all photos 5. // that have been viewed 6. viewed: function() { 7. return this.filter(function(photo){ 8. return photo.get('viewed'); 9. }); 10. }, 11. // Filter down the list to only photos that 12. // have not yet been viewed 13. unviewed: function() { 14. return this.without.apply(this, this.viewed()); 15. } 16.});
  • 22. PLAN 1. Introduction. 2. MVC and other models in JavaScript. 3. Third party library for Backbone. 4. Model with Backbone. 5. Collection with Backbone. 6. View with Backbone. 7. Demo. 8. Question and Answer?
  • 23. VIEW • Visual representation of models . • Observes a model and is notified when the model changes  update accordingly. • View in Backbone isn’t a CONTROLLER , it just can add an event listener to delegate handling the behavior to the controller.
  • 24. 1.var buildPhotoView = function( photoModel, photoController ){ 2. var base = document.createElement('div'), 3. photoEl = document.createElement('div'); 4. base.appendChild(photoEl); 5. var render= function(){ 6. // We use a templating library such as Underscore 7. // templating which generates the HTML for our photo entry 8. photoEl.innerHTML = _.template('photoTemplate', {src: photoModel.getSrc()}); 9. } 10. photoModel.addSubscriber( render ); 11. photoEl.addEventListener('click', function(){ 12. photoController.handleEvent('click', photoModel ); 13. }); 14. var show = function(){ 15. photoEl.style.display = ''; 16. } 17. var hide = function(){ 18. photoEl.style.display = 'none'; 19. } 20. return{ 21. showView: show, 22. hideView: hide 23. } 24.}
  • 25. CONTROLLER • Backbone didn’t actually provide a Controller. • In Backbone, View and Router does a little similar to a Controller. • Router binds the event for a Model and have View for respond to this event. 1. var PhotoRouter = Backbone.Router.extend({ 2. routes: { "photos/:id": "route" }, 3. route: function(id) { 4. var item = photoCollection.get(id); 5. var view = new PhotoView({ model: item }); 6. something.html( view.render().el ); 7. } 8. }):
  • 26. BENEFITS OF MVC 1. Easier overall maintenance. 2. Decoupling models and views  easy to write unit test and business logic. 3. Duplication of low-level model and controller code is eliminated across the application. 4. Work simultaneously between core logic and user interface.
  • 27. NOTES • Core components: Model, View, Collection, Router. • Complete documentation. • Used by large companies such as SoundCloud and Foursquare. • Event-driven communication. • No default templating engine. • Clear and flexible conventions for structuring applications. • …
  • 28. PLUGIN • Deeply nested models: • Backbone Relational • Ligament • Store data: • Backbone localStorage • Small Backbone ORM • View: • LayoutManager • Backbone.Marionette • More at here.
  • 29. DEMO • Other demo can view here: • Todos • Backbone Google Book • Todos of Niquet • …
  • 31. THANK YOU FOR YOUR ATTENTIONS !

Notas do Editor

  1. Models manage the data for an application. They are concerned with neither the user-interface nor presentation layers but instead represent unique forms of data that an application may require. When a model changes (e.g when it is updated), it will typically notify its observers (e.g views, a concept we will cover shortly) that a change has occurred so that they may react accordingly.To understand models further, let us imagine we have a JavaScript photo gallery application. In a photo gallery, the concept of a photo would merit its own model as it represents a unique kind of domain-specific data. Such a model may contain related attributes such as a caption, image source and additional meta-data. A specific photo would be stored in an instance of a model and a model may also be reusable. Below we can see an example of a very simplistic model implemented using Backbone.The built-in capabilities of models vary across frameworks, however it is quite common for them to support validation of attributes, where attributes represent the properties of the model, such as a model identifier. When using models in real-world applications we generally also desire model persistence. Persistence allows us to edit and update models with the knowledge that its most recent state will be saved in either: memory, in a user&apos;s localStorage data-store or synchronized with a database.In addition, a model may also have multiple views observing it. If say, our photo model contained meta-data such as its location (longitude and latitude), friends that were present in the a photo (a list of identifiers) and a list of tags, a developer may decide to provide a single view to display each of these three facets.It is not uncommon for modern MVC/MV* frameworks to provide a means to group models together (e.g in Backbone, these groups are referred to as &quot;collections&quot;). Managing models in groups allows us to write application logic based on notifications from the group should any model it contains be changed. This avoids the need to manually observe individual model instances.