SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

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