SlideShare a Scribd company logo
CLIENT-SIDE MVC
                         A brief introduction by Thomas Gorissen

Freitag, 11. März 2011
ME?
                         1996
                                • <blink>Hello World</blink>

                                • “WebMaster”

                                • JS/PHP
                         1999

                                • Starcraft




                                                               http://thomasgorissen.com
                                • C#   .NET / Forms
                         2005


                                • Ruby

                                • ASP   MVC
                         2010   • JS

Freitag, 11. März 2011
is
    • Model/View/Controller                    • Structure   provider
        Javascript Framework
                                               • RESTful   JSON Connector
    • Released           13th Oct 2010
                                               • Hash-Routing    Engine
    • @DocumentCloud
        project                                • Event-driven

    • MIT            licensed and on GitHub    • Lightweight   (6.9kb)


Freitag, 11. März 2011
is not


                         • DOM Accessor

                         • Animation   toolkit

                         • Control   suite

                         • All   in wonder package



Freitag, 11. März 2011
WHAT IS IT FOR?


                            All Client-Side
                         Rendered Applications



Freitag, 11. März 2011
AHA, HOW IS THAT?
     • If  you do a lot of
         JavaScript, things tend to   Model          Controller
         get messy!

     • Backbone    provides a way
         to organize your code, by            View
         using the MVC pattern

     • Only   the View accesses
         the DOM (e.g. with                   DOM

         jQuery, Zepto, ...)

Freitag, 11. März 2011
ALTHOUGH...

                                                                   outi neng-
                                                                  R Controller
                                                                     ngi
                                                    Model
    • ... it’s           a bit wrongly labeled
                                                 + Collection
                                                                   E

    •I     call it a “dirty” MVC                        ConViewoller
                                                            tr


                                                                 iew
                                                                VDOM

Freitag, 11. März 2011
THE MODEL
                         var Tweet = Backbone.Model.extend({

                         !     // Overrides
                         !     initialize: function(params) {
                         !     !       if(params.id && !params.text)
                         !     !       !    this.fetch();
                         !     },
                         !
                         !     url: function() {
                         !     !      return "http://twitter.com/statuses/show/" + this.id +".json";
                         !     },
                         !
                         !     defaults: {!
                         !     !    highlighted: false
                         !     },
                         !
                         !     // Custom function
                         !     highlight: function() {
                         !     !     this.set({
                         !     !     !     highlighted: !this.get("highlighted")
                         !     !     });
                         !     }

                         });


Freitag, 11. März 2011
THE MODEL
                                                 Functions/Params
    • Easy               to auto generate        •
                                                 •
                                                     – extend
                                                     – constructor / initialize
                                                 •   – get
                                                 •   – escape
                                                 •   – set

    • Holds               data better then the   •
                                                 •
                                                     – unset
                                                     – clear


        DOM                                      •
                                                 •
                                                 •
                                                     – id
                                                     – cid
                                                     – attributes
                                                 •   – defaults
                                                 •   - toJSON

    • Throws                change events        •
                                                 •
                                                     – fetch
                                                     – save
                                                 •   – destroy
                                                 •   – validate
                                                 •   – url

    • Can    connect to a URL to                 •
                                                 •
                                                     – parse
                                                     – clone


        populate from or persist to              •   – isNew
                                                 •   – change
                                                 •   – hasChanged

        the server                               •
                                                 •
                                                     – changedAttributes
                                                     – previous
                                                 •   – previousAttributes




Freitag, 11. März 2011
THE COLLECTION

                         var UserTweets = Backbone.Collection.extend({

                         !         // Overrides
                         !         model: Tweet,
                         !
                         !         url: function() {
                         !         !      return "http://twitter.com/statuses/user_timeline/" + this.user + ".json?count=10";
                         !         },
                         !
                         !         // Custom function
                         !         highlighted: function() {
                                   !     return this.filter(function(tweet) {
                                   !     !    return tweet.get('highlighted');
                                   !     });
                               }

                         });




Freitag, 11. März 2011
THE COLLECTION
    • Easy               to auto generate, as well   Functions/Params
                                                     •   – extend                     ◦   forEach (each)
                                                     •   – model                      ◦   map
                                                     •                                ◦   reduce (foldl, inject)
    • For    bulk handling model
                                                         – constructor / initialize
                                                     •   – models                     ◦   reduceRight (foldr)
                                                     •   – toJSON                     ◦   find (detect)

         objects                                     •
                                                     •
                                                         – Underscore Methods (25)
                                                         – add
                                                                                      ◦
                                                                                      ◦
                                                                                          filter (select)
                                                                                          reject
                                                     •   – remove                     ◦   every (all)
                                                     •   – get                        ◦   some (any)
                                                     •   – getByCid                       include
    • Throws                change events
                                                                                      ◦
                                                     •   – at
                                                                                      ◦   invoke
                                                     •   – length
                                                                                      ◦   max
                                                     •   – comparator
                                                                                      ◦   min
                                                     •   – sort
                                                                                      ◦   sortBy
                                                     •
    • Can    connect to a URL to
                                                         – pluck
                                                                                      ◦   sortedIndex
                                                     •   – url
                                                                                      ◦   toArray
                                                     •   – parse

         populate from the server
                                                                                      ◦   size
                                                     •   – fetch
                                                     •   – refresh                    ◦   first
                                                     •   – create                     ◦   rest
                                                                                      ◦   last
                                                                                      ◦   without

    • Tons               of query functions                                           ◦
                                                                                      ◦
                                                                                          indexOf
                                                                                          lastIndexOf
                                                                                      ◦   isEmpty
                                                                                      ◦   chain



Freitag, 11. März 2011
THE VIEW
                                                   or th                        e cont roller

                         var TweetView = Backbone.View.extend({
                         !
                         ! initialize: function() {
                         ! !       _.bindAll(this, "render");
                         ! !       this.model.bind("change", this.render);
                         ! },
                         ! !
                         ! events: {
                         ! !       "click": "highlight"
                         ! },
                         !
                         ! render: function() {
                         ! !       this.el = this.make("li", {
                         ! !       !     className: this.model.get("highlighted") ? "highlighted" : "normal"
                         ! !       }, this.model.get("text"));
                         ! !       return this;
                         ! },
                         !
                         ! highlight: function() {
                         ! !       this.model.highlight();
                         ! }
                         !
                         });


Freitag, 11. März 2011
THE VIEWe cont
                                        or th
                                                  roller




    • Changes            the DOM           Functions/Params
                                             •
    • Delegates          DOM events
                                                 – extend
                                             •   – constructor / initialize
                                             •   – el
                                             •   – $ (jQuery or Zepto)
                                             •   – render

    • Subscribes  Model/Collection           •   – remove
                                             •   – make
                                             •   – delegateEvents

        change events




Freitag, 11. März 2011
THE CONTROLLER ngine
                                      e rou t i n g- e
                                                                   or t h

                         var Workspace = Backbone.Controller.extend({

                         !     routes: {
                         !     !    "help":! !  !     !   !    "help",! !   // #help
                         !     !    "search/:name":! !    !    "search",!
                                                                        !   // #search/serrynaimo
                                 !  "search/:name/t:tweet":!   "search"!!   // #search/serrynaimo/t36732
                             ! },
                         !
                          ! help: function() {
                         ! !      ...
                          ! },

                          ! search: function(name, tweet) {
                         ! !     ...
                          ! }

                         });

                         new Workspace();
                         Backbone.history.start(); ! !    !    !   !    !   // Start url-change listener



Freitag, 11. März 2011
THE CONTROLLER ngine
                                    e rou t i n g- e
                                           or t h


    • Useful     to initiate application
         states like
         window.location.hash = "help";             Functions/Params
                                                     •   - extend
                                                     •
    • Enables   go back/forward
                                                         – routes
                                                     •   – constructor / initialize
                                                     •   – route

         browser functionality                       •   – saveLocation




    • Makes   application states
         bookmarkable


Freitag, 11. März 2011
DEMO


                         Download files here



Freitag, 11. März 2011
WHAT ELSE?

             • Make      many small JavaScript files for big dev teams

             • Comment       your code (e.g. yDoc compatible)

             • Works      absolutely great with html5boilerplate.com




Freitag, 11. März 2011
WE’RE HIRING!
                Mail me: thomas@adzcentral.com




                          @SERRYNAIMO
                         for JavaScript related fuzziness



Freitag, 11. März 2011

More Related Content

Recently uploaded (20)

LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
6th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 20256th Power Grid Model Meetup - 21 May 2025
6th Power Grid Model Meetup - 21 May 2025
DanBrown980551
 
STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Backbone.js - A brief introduction

  • 1. CLIENT-SIDE MVC A brief introduction by Thomas Gorissen Freitag, 11. März 2011
  • 2. ME? 1996 • <blink>Hello World</blink> • “WebMaster” • JS/PHP 1999 • Starcraft http://thomasgorissen.com • C# .NET / Forms 2005 • Ruby • ASP MVC 2010 • JS Freitag, 11. März 2011
  • 3. is • Model/View/Controller • Structure provider Javascript Framework • RESTful JSON Connector • Released 13th Oct 2010 • Hash-Routing Engine • @DocumentCloud project • Event-driven • MIT licensed and on GitHub • Lightweight (6.9kb) Freitag, 11. März 2011
  • 4. is not • DOM Accessor • Animation toolkit • Control suite • All in wonder package Freitag, 11. März 2011
  • 5. WHAT IS IT FOR? All Client-Side Rendered Applications Freitag, 11. März 2011
  • 6. AHA, HOW IS THAT? • If you do a lot of JavaScript, things tend to Model Controller get messy! • Backbone provides a way to organize your code, by View using the MVC pattern • Only the View accesses the DOM (e.g. with DOM jQuery, Zepto, ...) Freitag, 11. März 2011
  • 7. ALTHOUGH... outi neng- R Controller ngi Model • ... it’s a bit wrongly labeled + Collection E •I call it a “dirty” MVC ConViewoller tr iew VDOM Freitag, 11. März 2011
  • 8. THE MODEL var Tweet = Backbone.Model.extend({ ! // Overrides ! initialize: function(params) { ! ! if(params.id && !params.text) ! ! ! this.fetch(); ! }, ! ! url: function() { ! ! return "http://twitter.com/statuses/show/" + this.id +".json"; ! }, ! ! defaults: {! ! ! highlighted: false ! }, ! ! // Custom function ! highlight: function() { ! ! this.set({ ! ! ! highlighted: !this.get("highlighted") ! ! }); ! } }); Freitag, 11. März 2011
  • 9. THE MODEL Functions/Params • Easy to auto generate • • – extend – constructor / initialize • – get • – escape • – set • Holds data better then the • • – unset – clear DOM • • • – id – cid – attributes • – defaults • - toJSON • Throws change events • • – fetch – save • – destroy • – validate • – url • Can connect to a URL to • • – parse – clone populate from or persist to • – isNew • – change • – hasChanged the server • • – changedAttributes – previous • – previousAttributes Freitag, 11. März 2011
  • 10. THE COLLECTION var UserTweets = Backbone.Collection.extend({ ! // Overrides ! model: Tweet, ! ! url: function() { ! ! return "http://twitter.com/statuses/user_timeline/" + this.user + ".json?count=10"; ! }, ! ! // Custom function ! highlighted: function() { ! return this.filter(function(tweet) { ! ! return tweet.get('highlighted'); ! }); } }); Freitag, 11. März 2011
  • 11. THE COLLECTION • Easy to auto generate, as well Functions/Params • – extend ◦ forEach (each) • – model ◦ map • ◦ reduce (foldl, inject) • For bulk handling model – constructor / initialize • – models ◦ reduceRight (foldr) • – toJSON ◦ find (detect) objects • • – Underscore Methods (25) – add ◦ ◦ filter (select) reject • – remove ◦ every (all) • – get ◦ some (any) • – getByCid include • Throws change events ◦ • – at ◦ invoke • – length ◦ max • – comparator ◦ min • – sort ◦ sortBy • • Can connect to a URL to – pluck ◦ sortedIndex • – url ◦ toArray • – parse populate from the server ◦ size • – fetch • – refresh ◦ first • – create ◦ rest ◦ last ◦ without • Tons of query functions ◦ ◦ indexOf lastIndexOf ◦ isEmpty ◦ chain Freitag, 11. März 2011
  • 12. THE VIEW or th e cont roller var TweetView = Backbone.View.extend({ ! ! initialize: function() { ! ! _.bindAll(this, "render"); ! ! this.model.bind("change", this.render); ! }, ! ! ! events: { ! ! "click": "highlight" ! }, ! ! render: function() { ! ! this.el = this.make("li", { ! ! ! className: this.model.get("highlighted") ? "highlighted" : "normal" ! ! }, this.model.get("text")); ! ! return this; ! }, ! ! highlight: function() { ! ! this.model.highlight(); ! } ! }); Freitag, 11. März 2011
  • 13. THE VIEWe cont or th roller • Changes the DOM Functions/Params • • Delegates DOM events – extend • – constructor / initialize • – el • – $ (jQuery or Zepto) • – render • Subscribes Model/Collection • – remove • – make • – delegateEvents change events Freitag, 11. März 2011
  • 14. THE CONTROLLER ngine e rou t i n g- e or t h var Workspace = Backbone.Controller.extend({ ! routes: { ! ! "help":! ! ! ! ! "help",! ! // #help ! ! "search/:name":! ! ! "search",! ! // #search/serrynaimo ! "search/:name/t:tweet":! "search"!! // #search/serrynaimo/t36732 ! }, ! ! help: function() { ! ! ... ! }, ! search: function(name, tweet) { ! ! ... ! } }); new Workspace(); Backbone.history.start(); ! ! ! ! ! ! // Start url-change listener Freitag, 11. März 2011
  • 15. THE CONTROLLER ngine e rou t i n g- e or t h • Useful to initiate application states like window.location.hash = "help"; Functions/Params • - extend • • Enables go back/forward – routes • – constructor / initialize • – route browser functionality • – saveLocation • Makes application states bookmarkable Freitag, 11. März 2011
  • 16. DEMO Download files here Freitag, 11. März 2011
  • 17. WHAT ELSE? • Make many small JavaScript files for big dev teams • Comment your code (e.g. yDoc compatible) • Works absolutely great with html5boilerplate.com Freitag, 11. März 2011
  • 18. WE’RE HIRING! Mail me: [email protected] @SERRYNAIMO for JavaScript related fuzziness Freitag, 11. März 2011