SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
Backbone
                          John Ashmead




Wednesday, May 2, 2012                   1
MVC Abstraction Layer

                   • Events
                   • Models
                   • Views
                   • Collections
                   • Routers
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              2
Events
                   • Used for backbone’s events
                   • On, off, trigger
                   • You can role your own, e.g. “selected:true”
                   • Simple linked list
                   • Per instance
                   • Mixed into Models,Views, Collections, &
                         Routers
john.ashmead@ashmeadsoftware.com            Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                       3
Event calls
    object.on(event, callback, [context]);
    // aka bind

    object.off([event], [callback],
    [context]);

    // aka unbind
    object.trigger(event, [*args]);

    // event = name[:namespace]
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              4
Models

                   • A unique ‘cId’ supplied, you set ‘id’
                   • “change” events issued when you use get,
                         set to change (you can bypass)
                   • toJSON, fetch, parse, clone, previous,
                         previousAttributes, save, destroy, validate,
                         …


john.ashmead@ashmeadsoftware.com                 Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                            5
Model calls
    var MasterPiece =
    Backbone.Model.extend({
        option1: value1,
        initialize: function(arg1, …) {}
    });

    masterPiece1 = new MasterPiece();

    masterPiece1.get('option1');

    masterPiece1.set('option1', 'value1');
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              6
RESTful interface
            • “Backbone.sync” is basic call
            • Sends server a “POST”, “GET”, “PUT”, or
                   “DELETE”, depending on whether you have
                   requested a create, retrieve, update, or delete.
            • If you define MasterPiece.url(), sync will talk to
                   url’s of the form it returns

            • Example: /masterpieces/1
            • “isNew” tracks status on client
john.ashmead@ashmeadsoftware.com              Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                         7
Views

                   • Always gets a default ‘el’ DOM element
                   • Has view.$el defined as $(view.el) as well
                   • Use “setElement” to change its element
                   • Instantiate “render” method to get it to
                         work


john.ashmead@ashmeadsoftware.com            Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                       8
View code
     var Picture = Backbone.View.extend({
       render: function(eventName) {
          this.$el.html(this.template(
            this.model.toJSON()));
          return this;
       },
       events: {“change”: “render”},
       template: _.template(“<div><%= title =%></
     div>”),
       close: {
          this.$el.unbind();
          this.$el.empty();
     });
     var picture1 = new Picture({ model:
       monaLisa1 });
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              9
Collections
                   • Ordered sets of models
                   • Can be the “model” in a view
                   • Can be included in a model
                   • Usual functions, including most of
                         Underscore
                   • Models have a “collection” property, so
                         only one collection per model

john.ashmead@ashmeadsoftware.com              Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                         10
Underscore

                   • Each, map, find, filter, reject,…
                   • First, last, flatten, uniq, …
                   • Memoize, delay, throttle, …
                   • Keys, values, extend, clone, defaults, …

john.ashmead@ashmeadsoftware.com             Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                        11
Routers

                   • Keeps a map of hashtags to functions
                   • Calls the function
                   • Fires the event
                   • Uses the “hashchange” event from browser
                         or else polls the current location


john.ashmead@ashmeadsoftware.com                Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                           12
Router code
            var Dispatcher =
            Backbone.Router.extend({
              routes: {
                 “help”: “help”,
                 “search/:query”: “search”
              },
              help: function(){},
              search: function(query){…}
              );
            Backbone.history.start(); //magic
            <a href=”#/search/daVinci” />
            dispatcher1.search(“daVinci”);
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              13
More than one way to do it
         For views: model.view or
         model.views[], or fire events, or
         create “controller” object to
         mediate, …
         For sync: can sync per model, send
         sets of requests, …
         For events: can mixin to any JS
         object, create custom events, …
         For render: can use templates,
         direct DOM manip, jQuery UI, …
john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              14
More than one place that’s
                using it
                   • LinkedIn Mobile
                   • Foursquare
                   • Khan Academy
                   • Groupon Now!
                   • Pandora
john.ashmead@ashmeadsoftware.com       Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                  15
More than one place
                          it’s documented
               • http://documentcloud.github.com/backbone/
               • http://documentcloud.github.com/backbone/
                         docs/backbone.html
               • http://backbonetutorials.com/
               • http://blog.galk.me/post/17139384615/backbone-
                         js-tutorial-create-a-simple-twitter-search

john.ashmead@ashmeadsoftware.com                  Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                             16
Presented for your
                             consideration:
                              • Takes care of basics of MVC
                              • Small, clean, & friendly code
                              • Flexible
                              • Reduces need to figure this
                                   stuff out yourself


john.ashmead@ashmeadsoftware.com        Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                                   17
Backbone.js




john.ashmead@ashmeadsoftware.com   Backbone-PhillyCoders-5/2/2012
Wednesday, May 2, 2012                                              18

Más contenido relacionado

La actualidad más candente

JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patternsStoyan Stefanov
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQueryPaul Bakaus
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQueryDoug Neiner
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)Addy Osmani
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionPaul Irish
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
OOCSS for Javascript pirates at jQueryPgh meetup
OOCSS for Javascript pirates at jQueryPgh meetupOOCSS for Javascript pirates at jQueryPgh meetup
OOCSS for Javascript pirates at jQueryPgh meetupBrian Cavalier
 
Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)Marc Grabanski
 
Client-side MVC with Backbone.js
Client-side MVC with Backbone.js Client-side MVC with Backbone.js
Client-side MVC with Backbone.js iloveigloo
 

La actualidad más candente (18)

Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQuery
 
jQuery-3-UI
jQuery-3-UIjQuery-3-UI
jQuery-3-UI
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQuery
 
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
 
jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
OOCSS for Javascript pirates at jQueryPgh meetup
OOCSS for Javascript pirates at jQueryPgh meetupOOCSS for Javascript pirates at jQueryPgh meetup
OOCSS for Javascript pirates at jQueryPgh meetup
 
Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)Whirlwind Tour of SVG (plus RaphaelJS)
Whirlwind Tour of SVG (plus RaphaelJS)
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Client-side MVC with Backbone.js
Client-side MVC with Backbone.js Client-side MVC with Backbone.js
Client-side MVC with Backbone.js
 

Similar a Overview of Backbone

JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance PatternsStoyan Stefanov
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster WebEric Bidelman
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in MuleShahid Shaik
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeDavid Boike
 
SPSTC - SharePoint & jQuery Essentials
SPSTC - SharePoint & jQuery EssentialsSPSTC - SharePoint & jQuery Essentials
SPSTC - SharePoint & jQuery EssentialsMark Rackley
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Herman Peeren
 
Yii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading toYii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading toAlexander Makarov
 
Getting up & running with zend framework
Getting up & running with zend frameworkGetting up & running with zend framework
Getting up & running with zend frameworkSaidur Rahman
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with GradleAndres Almiray
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownMark Rackley
 

Similar a Overview of Backbone (20)

Grails 2.0 Update
Grails 2.0 UpdateGrails 2.0 Update
Grails 2.0 Update
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster Web
 
Maven introduction in Mule
Maven introduction in MuleMaven introduction in Mule
Maven introduction in Mule
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught Me
 
SPSTC - SharePoint & jQuery Essentials
SPSTC - SharePoint & jQuery EssentialsSPSTC - SharePoint & jQuery Essentials
SPSTC - SharePoint & jQuery Essentials
 
Wheel.js
Wheel.jsWheel.js
Wheel.js
 
Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!Jooctrine - Doctrine ORM in Joomla!
Jooctrine - Doctrine ORM in Joomla!
 
Yii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading toYii, frameworks and where PHP is heading to
Yii, frameworks and where PHP is heading to
 
Getting up & running with zend framework
Getting up & running with zend frameworkGetting up & running with zend framework
Getting up & running with zend framework
 
Getting up and running with Zend Framework
Getting up and running with Zend FrameworkGetting up and running with Zend Framework
Getting up and running with Zend Framework
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
Apache Maven 2 Part 2
Apache Maven 2 Part 2Apache Maven 2 Part 2
Apache Maven 2 Part 2
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
 
The Basics of Multisiting
The Basics of MultisitingThe Basics of Multisiting
The Basics of Multisiting
 
Maven
MavenMaven
Maven
 
Maven
MavenMaven
Maven
 
SPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have knownSPSDenver - SharePoint & jQuery - What I wish I would have known
SPSDenver - SharePoint & jQuery - What I wish I would have known
 

Más de John Ashmead

The Quantum Internet: Hype or the Next Step
The Quantum Internet:  Hype or the Next StepThe Quantum Internet:  Hype or the Next Step
The Quantum Internet: Hype or the Next StepJohn Ashmead
 
How to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyHow to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyJohn Ashmead
 
The Quantum Internet: Hype or the Next Step
The Quantum Internet:  Hype or the Next StepThe Quantum Internet:  Hype or the Next Step
The Quantum Internet: Hype or the Next StepJohn Ashmead
 
Artificial Intelligence: Past, Present, Futures
Artificial Intelligence:  Past, Present, FuturesArtificial Intelligence:  Past, Present, Futures
Artificial Intelligence: Past, Present, FuturesJohn Ashmead
 
Time dispersion in time-of-arrival measurements
Time dispersion in time-of-arrival measurementsTime dispersion in time-of-arrival measurements
Time dispersion in time-of-arrival measurementsJohn Ashmead
 
Time dispersion in quantum mechanics -- Philcon 2019 version
Time dispersion in quantum mechanics -- Philcon 2019 versionTime dispersion in quantum mechanics -- Philcon 2019 version
Time dispersion in quantum mechanics -- Philcon 2019 versionJohn Ashmead
 
Time dispersion in quantum mechanics
Time dispersion in quantum mechanicsTime dispersion in quantum mechanics
Time dispersion in quantum mechanicsJohn Ashmead
 
Practical Telepathy: The Science & Engineering of Mind-Reading
Practical Telepathy:  The Science & Engineering of Mind-ReadingPractical Telepathy:  The Science & Engineering of Mind-Reading
Practical Telepathy: The Science & Engineering of Mind-ReadingJohn Ashmead
 
From Startup to Mature Company: PostgreSQL Tips and techniques
From Startup to Mature Company:  PostgreSQL Tips and techniquesFrom Startup to Mature Company:  PostgreSQL Tips and techniques
From Startup to Mature Company: PostgreSQL Tips and techniquesJohn Ashmead
 
Practical Telepathy: The Science & Engineering of Mind-Reading
Practical Telepathy:  The Science & Engineering of Mind-ReadingPractical Telepathy:  The Science & Engineering of Mind-Reading
Practical Telepathy: The Science & Engineering of Mind-ReadingJohn Ashmead
 
Stargates: Theory and Practice
Stargates:  Theory and PracticeStargates:  Theory and Practice
Stargates: Theory and PracticeJohn Ashmead
 
StarGates: Theory and Practice
StarGates:  Theory and PracticeStarGates:  Theory and Practice
StarGates: Theory and PracticeJohn Ashmead
 
Star Gates: the Theory and Practice
Star Gates:  the Theory and PracticeStar Gates:  the Theory and Practice
Star Gates: the Theory and PracticeJohn Ashmead
 
Time to the power of Tim
Time to the power of TimTime to the power of Tim
Time to the power of TimJohn Ashmead
 
How many universes are there, anyway
How many universes are there, anywayHow many universes are there, anyway
How many universes are there, anywayJohn Ashmead
 
A Quantum of Mystery
A Quantum of MysteryA Quantum of Mystery
A Quantum of MysteryJohn Ashmead
 
Converting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLConverting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLJohn Ashmead
 
Seven War Stories and a Moral
Seven War Stories and a MoralSeven War Stories and a Moral
Seven War Stories and a MoralJohn Ashmead
 

Más de John Ashmead (20)

The Quantum Internet: Hype or the Next Step
The Quantum Internet:  Hype or the Next StepThe Quantum Internet:  Hype or the Next Step
The Quantum Internet: Hype or the Next Step
 
How to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quicklyHow to build a PostgreSQL-backed website quickly
How to build a PostgreSQL-backed website quickly
 
The Quantum Internet: Hype or the Next Step
The Quantum Internet:  Hype or the Next StepThe Quantum Internet:  Hype or the Next Step
The Quantum Internet: Hype or the Next Step
 
Artificial Intelligence: Past, Present, Futures
Artificial Intelligence:  Past, Present, FuturesArtificial Intelligence:  Past, Present, Futures
Artificial Intelligence: Past, Present, Futures
 
Time dispersion in time-of-arrival measurements
Time dispersion in time-of-arrival measurementsTime dispersion in time-of-arrival measurements
Time dispersion in time-of-arrival measurements
 
Time dispersion in quantum mechanics -- Philcon 2019 version
Time dispersion in quantum mechanics -- Philcon 2019 versionTime dispersion in quantum mechanics -- Philcon 2019 version
Time dispersion in quantum mechanics -- Philcon 2019 version
 
Time dispersion in quantum mechanics
Time dispersion in quantum mechanicsTime dispersion in quantum mechanics
Time dispersion in quantum mechanics
 
Mars Or Bust!
Mars Or Bust!Mars Or Bust!
Mars Or Bust!
 
Practical Telepathy: The Science & Engineering of Mind-Reading
Practical Telepathy:  The Science & Engineering of Mind-ReadingPractical Telepathy:  The Science & Engineering of Mind-Reading
Practical Telepathy: The Science & Engineering of Mind-Reading
 
From Startup to Mature Company: PostgreSQL Tips and techniques
From Startup to Mature Company:  PostgreSQL Tips and techniquesFrom Startup to Mature Company:  PostgreSQL Tips and techniques
From Startup to Mature Company: PostgreSQL Tips and techniques
 
Practical Telepathy: The Science & Engineering of Mind-Reading
Practical Telepathy:  The Science & Engineering of Mind-ReadingPractical Telepathy:  The Science & Engineering of Mind-Reading
Practical Telepathy: The Science & Engineering of Mind-Reading
 
Stargates: Theory and Practice
Stargates:  Theory and PracticeStargates:  Theory and Practice
Stargates: Theory and Practice
 
StarGates: Theory and Practice
StarGates:  Theory and PracticeStarGates:  Theory and Practice
StarGates: Theory and Practice
 
Quantum dots
Quantum dotsQuantum dots
Quantum dots
 
Star Gates: the Theory and Practice
Star Gates:  the Theory and PracticeStar Gates:  the Theory and Practice
Star Gates: the Theory and Practice
 
Time to the power of Tim
Time to the power of TimTime to the power of Tim
Time to the power of Tim
 
How many universes are there, anyway
How many universes are there, anywayHow many universes are there, anyway
How many universes are there, anyway
 
A Quantum of Mystery
A Quantum of MysteryA Quantum of Mystery
A Quantum of Mystery
 
Converting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQLConverting from MySQL to PostgreSQL
Converting from MySQL to PostgreSQL
 
Seven War Stories and a Moral
Seven War Stories and a MoralSeven War Stories and a Moral
Seven War Stories and a Moral
 

Último

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 

Último (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Overview of Backbone

  • 1. Backbone John Ashmead Wednesday, May 2, 2012 1
  • 2. MVC Abstraction Layer • Events • Models • Views • Collections • Routers john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 2
  • 3. Events • Used for backbone’s events • On, off, trigger • You can role your own, e.g. “selected:true” • Simple linked list • Per instance • Mixed into Models,Views, Collections, & Routers john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 3
  • 4. Event calls object.on(event, callback, [context]); // aka bind object.off([event], [callback], [context]); // aka unbind object.trigger(event, [*args]); // event = name[:namespace] john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 4
  • 5. Models • A unique ‘cId’ supplied, you set ‘id’ • “change” events issued when you use get, set to change (you can bypass) • toJSON, fetch, parse, clone, previous, previousAttributes, save, destroy, validate, … john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 5
  • 6. Model calls var MasterPiece = Backbone.Model.extend({ option1: value1, initialize: function(arg1, …) {} }); masterPiece1 = new MasterPiece(); masterPiece1.get('option1'); masterPiece1.set('option1', 'value1'); john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 6
  • 7. RESTful interface • “Backbone.sync” is basic call • Sends server a “POST”, “GET”, “PUT”, or “DELETE”, depending on whether you have requested a create, retrieve, update, or delete. • If you define MasterPiece.url(), sync will talk to url’s of the form it returns • Example: /masterpieces/1 • “isNew” tracks status on client john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 7
  • 8. Views • Always gets a default ‘el’ DOM element • Has view.$el defined as $(view.el) as well • Use “setElement” to change its element • Instantiate “render” method to get it to work john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 8
  • 9. View code var Picture = Backbone.View.extend({ render: function(eventName) { this.$el.html(this.template( this.model.toJSON())); return this; }, events: {“change”: “render”}, template: _.template(“<div><%= title =%></ div>”), close: { this.$el.unbind(); this.$el.empty(); }); var picture1 = new Picture({ model: monaLisa1 }); john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 9
  • 10. Collections • Ordered sets of models • Can be the “model” in a view • Can be included in a model • Usual functions, including most of Underscore • Models have a “collection” property, so only one collection per model john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 10
  • 11. Underscore • Each, map, find, filter, reject,… • First, last, flatten, uniq, … • Memoize, delay, throttle, … • Keys, values, extend, clone, defaults, … john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 11
  • 12. Routers • Keeps a map of hashtags to functions • Calls the function • Fires the event • Uses the “hashchange” event from browser or else polls the current location john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 12
  • 13. Router code var Dispatcher = Backbone.Router.extend({ routes: { “help”: “help”, “search/:query”: “search” }, help: function(){}, search: function(query){…} ); Backbone.history.start(); //magic <a href=”#/search/daVinci” /> dispatcher1.search(“daVinci”); john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 13
  • 14. More than one way to do it For views: model.view or model.views[], or fire events, or create “controller” object to mediate, … For sync: can sync per model, send sets of requests, … For events: can mixin to any JS object, create custom events, … For render: can use templates, direct DOM manip, jQuery UI, … john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 14
  • 15. More than one place that’s using it • LinkedIn Mobile • Foursquare • Khan Academy • Groupon Now! • Pandora john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 15
  • 16. More than one place it’s documented • http://documentcloud.github.com/backbone/ • http://documentcloud.github.com/backbone/ docs/backbone.html • http://backbonetutorials.com/ • http://blog.galk.me/post/17139384615/backbone- js-tutorial-create-a-simple-twitter-search john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 16
  • 17. Presented for your consideration: • Takes care of basics of MVC • Small, clean, & friendly code • Flexible • Reduces need to figure this stuff out yourself john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 17
  • 18. Backbone.js john.ashmead@ashmeadsoftware.com Backbone-PhillyCoders-5/2/2012 Wednesday, May 2, 2012 18