SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
Backbone.js
         Ivano Malavolta
    ivano.malavolta@univaq.it
http://www.di.univaq.it/malavolta
Roadmap

•   Why Backbone
•   Events
•   Model
•   Collection
•   View
•   Router
Why Backbone
We are building apps, not web sites

If your code is not structured:
• it is extremely easy that your web app
   becomes a big mess of html + css
   + javascript
• maintaining each part of your app asks
    for a deep analysis of ALL its aspects
   (logic, presentation, etc.)
• you may waste a whole day due to
   a missing “<“
What we want to avoid




Imagine yourself trying to change
• how a movie should be rendered in your app
• the REST API providing info about movies
Intuition

Backbone gives you STRUCTURE
Backbone

From the Backbone website...
                                         represent data




 manipulate            lists of models
  the DOM
Backbone (continued)
Backbone provides also features for:

• sync
   – for managing how to persist models
• events
   – for managing how data and control are exchanged
     within your app
• router
   – for managing the interaction flow among views
Roadmap

•   Why Backbone
•   Events
•   Models
•   Collections
•   Views
•   Router
Events

Events is a module that can be mixed in to any object

It gives the object the ability to bind and trigger
  custom named events

It is extremely useful for exchanging data and control
  among objects
object will react to
  the “alert” event
                       Events API
 (the “off” function
detaches the event)                        event parameters




                         the “alert” event is
                                fired
Roadmap

•   Why Backbone
•   Events
•   Models
•   Collections
•   Views
•   Router
Models
Models represent your data

Each model represent a data type in your app, together
  with the logic surrounding it, like:
• persistence
• conversions
• validations
• computed properties
• access control
Models

You extend Backbone.Model with your domain-specific
  methods, and Model provides a basic set of
  functionality for managing changes, like:

•   getter and setter
•   id
•   constructor
•   JSON persistance
Example of Model
custom method




                           setting an
                                         event fired
                           attribute
                                        when “color”
                                          changes


                                          custom
                                          method
                                        invocation
Model Constructor and Attributes

• initialize()
  initialize()
   – it is triggered every time you create a new instance of a
     model
   – it works also for collections and views
   – it can take an JS object for setting also attributes
• get() & set()
  get()
   – they are used to set and retrieve the value of certain
     attributes
• defaults
   – a property named 'defaults' in your model declaration
Example
Sync

Backbone.sync is the function that Backbone calls
  every time it attempts to read or save a model

By default, it uses Ajax to make a RESTful JSON
  request to a server
Sync Usage
Usually, you will not use the sync method directly you
                                             directly,
  will it implicitly when you call one of these methods

• Models
   – fetch: gets the most up-to-date values of the model instance
   – save: persists the model instance
   – destroy: deletes the model instance
• Collections
   – fetch
   – create
Sync

You can override it in order to use a different
  persistence strategy, such as:
• WebSockets
• Local Storage
• WebSQL




Backbone.sync is the default global function that all
  models use unless the models have a sync method
  specifically set
Sync Signature              example of overriden sync:
                              http://bit.ly/KWdxNN

The method signature of Backbone.sync is

      sync(method, model, [options])

• method the CRUD method ("create“, "read“, "update",
  method:
  or "delete")
• model the model (or collection) to be synced
  model:
• options – success and error callbacks, and all other
  jQuery request options
Roadmap

•   Why Backbone
•   Events
•   Models
•   Collections
•   Views
•   Router
Collections

Collections are ordered sets of models

You can
• bind "change" events to be notified when any model
  in the collection has been modified
• listen for "add" and "remove"events
• fetch the collection from the server (or other
  persistence layer)
Collections

Any event that is triggered on a model in a collection
  will also be triggered on the collection directly

The model attribute of a collection represents the
  kind of model that can be stored in it
Example
Collection Methods
Methods on collections include:

•   fetch:
    fetch gets all the models of a collection
•   create:
    create creates a new model within the collection
•   reset:
    reset updates the collection in bulk
•   add: adds a model to the collection
    add
•   remove:
    remove removes a model from the collection
•   at:
    at returns a specific model from the collection
•   sort:
    sort sorts the collection
Roadmap

•   Why Backbone
•   Events
•   Models
•   Collections
•   Views
•   Router
Views

Views represent and manage the visible parts of your
  application

They are also used to listen to interaction events and
  react accordingly
Views

All views have a DOM element at all times, even if they
  are already in the page or not

   views can be rendered at any time, and inserted into
  the DOM all at once

   you get high-performance UI rendering with as few
  reflows and repaints as possible
View DOM element
this.el is a reference to the DOM element, it is
  created from:
• tagName
   – for example body, ul, span, img
• className
   – class name of some element within the DOM
• id
   – id of an element within the DOM


If none of them is specified, el is an empty <div>
View DOM render()
The render() method is used to update the this.el
  element with the new HTML

The default implementation of render is a no-op
   you have to override it to create the new HTML

Backbone is agnostic with respect to your code in
  render(), however...
     you are STRONGLY encouraged to use a
     Javascript templating library here
Example
Roadmap

•   Why Backbone
•   Events
•   Models
•   Collections
•   Views
•   Router
Router

Backbone.Router provides methods for routing client-
  side pages, and connecting them to actions and
  events

At a minimum, a router is composed of two main parts:

• routes
   – an hash that pairs routes to actions
• actions
   – JS functions triggered when certain routes are navigated
Routes
It is an hash that maps URLs to functions on your
  router

URLs fragments can also contain dynamic data via
  Backbone-specific URL parts:

• parameter
  – match a single URL component between slashes
• splat
  – match any number of URL components
Example
History

History serves as a global router to
1. handle hashchange events
2. match the appropriate route
3. trigger callbacks

You should never access it directly, you just need call
   Backbone.history.start() to begin
   monitoring hashchange events, and dispatching
   routes in your app
Summary: Classical Workflow
1. You dig into JSON objects
2. look up elements in the DOM
3. update the HTML by hand           you
               DOM
              events
  JS                   DOM
scripts
              DOM
             updates
                         interacts
      data & events

   data
  sources
Summary: Backbone
You organize your interface into logical views backed by models

Each view can be updated independently when the model
  changes, without having to redraw the page
                                         DOM
     model events                       events
                         View
                                                 DOM   interacts
                                     DOM
     Model      model updates       updates

        sync            routing

   data
  sources                  Router
Summary: Backbone

You can bind your view‘s render()
  function to the model‘s "change”
  event

   now everywhere that model data
  is displayed in the UI, it is always
  immediately up to date
References


http://backbonejs.org

Mais conteúdo relacionado

Mais procurados

[2015/2016] The REST architectural style
[2015/2016] The REST architectural style[2015/2016] The REST architectural style
[2015/2016] The REST architectural styleIvano Malavolta
 
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 developersAoteaStudios
 
HTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsHTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsIvano Malavolta
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVCAcquisio
 
J query presentation
J query presentationJ query presentation
J query presentationakanksha17
 
BackboneJS and friends
BackboneJS and friendsBackboneJS and friends
BackboneJS and friendsScott Cowan
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal Knowledge
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutAndoni Arroyo
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Michael Shrove
 
Cert05 70-487 - developing microsoft azure and web services
Cert05   70-487 - developing microsoft azure and web servicesCert05   70-487 - developing microsoft azure and web services
Cert05 70-487 - developing microsoft azure and web servicesDotNetCampus
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at DatacomDavid Xi Peng Yang
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascriptDsixE Inc
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 

Mais procurados (20)

[2015/2016] The REST architectural style
[2015/2016] The REST architectural style[2015/2016] The REST architectural style
[2015/2016] The REST architectural style
 
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
 
Fast mobile web apps
Fast mobile web appsFast mobile web apps
Fast mobile web apps
 
HTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsHTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile apps
 
Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...
Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...
Building rich Single Page Applications (SPAs) for desktop, mobile, and tablet...
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
Backbone js-slides
Backbone js-slidesBackbone js-slides
Backbone js-slides
 
J query presentation
J query presentationJ query presentation
J query presentation
 
BackboneJS and friends
BackboneJS and friendsBackboneJS and friends
BackboneJS and friends
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshop
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockout
 
Ajax
AjaxAjax
Ajax
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)
 
Cert05 70-487 - developing microsoft azure and web services
Cert05   70-487 - developing microsoft azure and web servicesCert05   70-487 - developing microsoft azure and web services
Cert05 70-487 - developing microsoft azure and web services
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascript
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 

Semelhante a Backbone.js

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
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
 
Backbone.js slides
Backbone.js slidesBackbone.js slides
Backbone.js slidesAmbert Ho
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO DevsWO Community
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
Client Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsClient Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsTom Z Zeng
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGentkevinvw
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)Igor Talevski
 
Backbonejs
BackbonejsBackbonejs
BackbonejsSam Lee
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatiasapientindia
 
Intro to emberjs
Intro to emberjsIntro to emberjs
Intro to emberjsMandy Pao
 

Semelhante a Backbone.js (20)

Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
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!
 
Ember vs Backbone
Ember vs BackboneEmber vs Backbone
Ember vs Backbone
 
Show Some Spine!
Show Some Spine!Show Some Spine!
Show Some Spine!
 
Backbone.js slides
Backbone.js slidesBackbone.js slides
Backbone.js slides
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Intro lift
Intro liftIntro lift
Intro lift
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
Client Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsClient Side MVC with Backbone and Rails
Client Side MVC with Backbone and Rails
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
AngularJS
AngularJSAngularJS
AngularJS
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 
Rp 6 session 2 naresh bhatia
Rp 6  session 2 naresh bhatiaRp 6  session 2 naresh bhatia
Rp 6 session 2 naresh bhatia
 
Intro to emberjs
Intro to emberjsIntro to emberjs
Intro to emberjs
 

Mais de Ivano Malavolta

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Ivano Malavolta
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)Ivano Malavolta
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green ITIvano Malavolta
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Ivano Malavolta
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]Ivano Malavolta
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Ivano Malavolta
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Ivano Malavolta
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Ivano Malavolta
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Ivano Malavolta
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Ivano Malavolta
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Ivano Malavolta
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Ivano Malavolta
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Ivano Malavolta
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile developmentIvano Malavolta
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architecturesIvano Malavolta
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design LanguageIvano Malavolta
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languagesIvano Malavolta
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software ArchitectureIvano Malavolta
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineeringIvano Malavolta
 

Mais de Ivano Malavolta (20)

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
 
The H2020 experience
The H2020 experienceThe H2020 experience
The H2020 experience
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green IT
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile development
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architectures
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languages
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering
 

Último

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Último (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

Backbone.js

  • 1. Backbone.js Ivano Malavolta ivano.malavolta@univaq.it http://www.di.univaq.it/malavolta
  • 2. Roadmap • Why Backbone • Events • Model • Collection • View • Router
  • 3. Why Backbone We are building apps, not web sites If your code is not structured: • it is extremely easy that your web app becomes a big mess of html + css + javascript • maintaining each part of your app asks for a deep analysis of ALL its aspects (logic, presentation, etc.) • you may waste a whole day due to a missing “<“
  • 4. What we want to avoid Imagine yourself trying to change • how a movie should be rendered in your app • the REST API providing info about movies
  • 6. Backbone From the Backbone website... represent data manipulate lists of models the DOM
  • 7. Backbone (continued) Backbone provides also features for: • sync – for managing how to persist models • events – for managing how data and control are exchanged within your app • router – for managing the interaction flow among views
  • 8. Roadmap • Why Backbone • Events • Models • Collections • Views • Router
  • 9. Events Events is a module that can be mixed in to any object It gives the object the ability to bind and trigger custom named events It is extremely useful for exchanging data and control among objects
  • 10. object will react to the “alert” event Events API (the “off” function detaches the event) event parameters the “alert” event is fired
  • 11. Roadmap • Why Backbone • Events • Models • Collections • Views • Router
  • 12. Models Models represent your data Each model represent a data type in your app, together with the logic surrounding it, like: • persistence • conversions • validations • computed properties • access control
  • 13. Models You extend Backbone.Model with your domain-specific methods, and Model provides a basic set of functionality for managing changes, like: • getter and setter • id • constructor • JSON persistance
  • 14. Example of Model custom method setting an event fired attribute when “color” changes custom method invocation
  • 15. Model Constructor and Attributes • initialize() initialize() – it is triggered every time you create a new instance of a model – it works also for collections and views – it can take an JS object for setting also attributes • get() & set() get() – they are used to set and retrieve the value of certain attributes • defaults – a property named 'defaults' in your model declaration
  • 17. Sync Backbone.sync is the function that Backbone calls every time it attempts to read or save a model By default, it uses Ajax to make a RESTful JSON request to a server
  • 18. Sync Usage Usually, you will not use the sync method directly you directly, will it implicitly when you call one of these methods • Models – fetch: gets the most up-to-date values of the model instance – save: persists the model instance – destroy: deletes the model instance • Collections – fetch – create
  • 19. Sync You can override it in order to use a different persistence strategy, such as: • WebSockets • Local Storage • WebSQL Backbone.sync is the default global function that all models use unless the models have a sync method specifically set
  • 20. Sync Signature example of overriden sync: http://bit.ly/KWdxNN The method signature of Backbone.sync is sync(method, model, [options]) • method the CRUD method ("create“, "read“, "update", method: or "delete") • model the model (or collection) to be synced model: • options – success and error callbacks, and all other jQuery request options
  • 21. Roadmap • Why Backbone • Events • Models • Collections • Views • Router
  • 22. Collections Collections are ordered sets of models You can • bind "change" events to be notified when any model in the collection has been modified • listen for "add" and "remove"events • fetch the collection from the server (or other persistence layer)
  • 23. Collections Any event that is triggered on a model in a collection will also be triggered on the collection directly The model attribute of a collection represents the kind of model that can be stored in it
  • 25. Collection Methods Methods on collections include: • fetch: fetch gets all the models of a collection • create: create creates a new model within the collection • reset: reset updates the collection in bulk • add: adds a model to the collection add • remove: remove removes a model from the collection • at: at returns a specific model from the collection • sort: sort sorts the collection
  • 26. Roadmap • Why Backbone • Events • Models • Collections • Views • Router
  • 27. Views Views represent and manage the visible parts of your application They are also used to listen to interaction events and react accordingly
  • 28. Views All views have a DOM element at all times, even if they are already in the page or not views can be rendered at any time, and inserted into the DOM all at once you get high-performance UI rendering with as few reflows and repaints as possible
  • 29. View DOM element this.el is a reference to the DOM element, it is created from: • tagName – for example body, ul, span, img • className – class name of some element within the DOM • id – id of an element within the DOM If none of them is specified, el is an empty <div>
  • 30. View DOM render() The render() method is used to update the this.el element with the new HTML The default implementation of render is a no-op you have to override it to create the new HTML Backbone is agnostic with respect to your code in render(), however... you are STRONGLY encouraged to use a Javascript templating library here
  • 32. Roadmap • Why Backbone • Events • Models • Collections • Views • Router
  • 33. Router Backbone.Router provides methods for routing client- side pages, and connecting them to actions and events At a minimum, a router is composed of two main parts: • routes – an hash that pairs routes to actions • actions – JS functions triggered when certain routes are navigated
  • 34. Routes It is an hash that maps URLs to functions on your router URLs fragments can also contain dynamic data via Backbone-specific URL parts: • parameter – match a single URL component between slashes • splat – match any number of URL components
  • 36. History History serves as a global router to 1. handle hashchange events 2. match the appropriate route 3. trigger callbacks You should never access it directly, you just need call Backbone.history.start() to begin monitoring hashchange events, and dispatching routes in your app
  • 37. Summary: Classical Workflow 1. You dig into JSON objects 2. look up elements in the DOM 3. update the HTML by hand you DOM events JS DOM scripts DOM updates interacts data & events data sources
  • 38. Summary: Backbone You organize your interface into logical views backed by models Each view can be updated independently when the model changes, without having to redraw the page DOM model events events View DOM interacts DOM Model model updates updates sync routing data sources Router
  • 39. Summary: Backbone You can bind your view‘s render() function to the model‘s "change” event now everywhere that model data is displayed in the UI, it is always immediately up to date