SlideShare una empresa de Scribd logo
1 de 20
Let’s Learn Backbone.js
building a re-usable table component
Key things to keep in mind from
the Throne of JS talk

✤   Clean code does not interleave concepts. Code that is around
    maintaining data should not be mixed with code messing with the
    DOM.

✤   DOM code should be focused, and not know about about other bits of
    DOM code.

✤   The source of truth should be in rich data structures, not embedded in
    the DOM.
Components of Backbone.js


✤   The Model, an abstraction over a single REST resource

✤   The Collection, an abstraction over a REST collection of resources

✤   The View, a logical UI component

✤   The Router, a way to maintain application state
The “real” pattern, MVP



✤   Backbone is MVP, Model View Presenter

✤   What backbone calls the view is actually the presenter, what it calls
    the template is actually the view

✤   This is confusing, but unimportant
Model / Collection



✤   Where the data goes

✤   Emits events when things change

✤   When in doubt, push it down
The View

✤   Operates on a single tree of elements

✤   Should never touch the html outside of its root element

✤   Should either be changing model/collection based on user
    interaction, or reacting to data changing

✤   Can be rendered without existing in the DOM

✤   Can be composed of multiple sub views
The Router


✤   When you have a “single page” application, you often still want the
    back button to work, and users to have the ability to “deep link”

✤   The router accomplishes this via either tricks with hash marks, or
    with push state

✤   Least fundamental of all the components
Thats it.
Backbone.Marionette

✤   Created by Derick Bailey, to provide structure in building larger
    javascript applications

✤   Philosophically very similar to backbone, just goes a few more steps

✤   Eliminates a lot of common boilerplate in backbone code by
    providing slightly higher level view abstractions

✤   Provides tools that become extremely useful when writing larger
    javascript applications
Marionette Views



✤   Provides a additional convenience methods on top of what backbone
    gives you (ui hash, triggers hash, model events hash (added by me :)

✤   Provides a model binder, to prevent zombie views

✤   Frameworks away basic rendering code
Marionette Views



✤   Item View, binds to a model

✤   Collection View, binds to a collection

✤   CompositeView, binds to a model and to a collection
Marionette Tools


✤   Application Modules: Lets you group parts of the application, and
    start/stop them independently

✤   Layouts/Regions: Manage the creation/displaying/disposing of
    parts of the page which are dynamic

✤   Event Aggregator: Provides a module/application level event bus

✤   AppRouter: Routers that delegate to external objects
Building a Table Editor
CommonJS (in the asset pipeline)

✤   Using global scope is explicit

✤   You bring in a module with var Reference = require(“path/to/
    module”)

✤   You choose what that Reference is by setting module.exports in the
    module

✤   You should never need to introduce a global variable

✤   Much nicer then ruby, but still behind a lot of other implementations
    (like python, clojure, scala, etc)
Function.apply

✤   Inside a function, what “this” refers to is determined by the
    invocation

✤   If invoked off of an object, “this” will refer to that object

✤   If invoked in isolation, “this” will refer to the global scope

✤   If invoked via apply (or call), “this” is specified by the caller

✤   apply also lets you pass an array that will be used as arguments (you
    apply arguments to a function)
Misc



✤   I have emacs set up to display function() as !(). This is purely
    cosmetic (it is still function when it saves) but I find it dramatically
    reduces the syntactic noise in the language.
What are our requirements?

✤   Have a “new” row. It has a “create” button that when clicked, creates
    a resource on the server. When that resource is created, it creates a
    new row.

✤   Rows can be edited and deleted.

✤   Errors are shown, and edit boxes are highlighted

✤   There should be a way to override things at any level

✤   There should be a simple api for consumers to invoke
Time to Code

Más contenido relacionado

La actualidad más candente

Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Christian Lilley
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
Andrew Lovett-Barron
 
Html5 and beyond the next generation of mobile web applications - Touch Tou...
Html5 and beyond   the next generation of mobile web applications - Touch Tou...Html5 and beyond   the next generation of mobile web applications - Touch Tou...
Html5 and beyond the next generation of mobile web applications - Touch Tou...
RIA RUI Society
 

La actualidad más candente (20)

Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
 
The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015The Art of AngularJS in 2015 - Angular Summit 2015
The Art of AngularJS in 2015 - Angular Summit 2015
 
The Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.jsThe Point of Vue - Intro to Vue.js
The Point of Vue - Intro to Vue.js
 
Advanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JSAdvanced Tips & Tricks for using Angular JS
Advanced Tips & Tricks for using Angular JS
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
 
Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and PromisesBeyond DOM Manipulations: Building Stateful Modules with Events and Promises
Beyond DOM Manipulations: Building Stateful Modules with Events and Promises
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Mobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScriptMobile HTML, CSS, and JavaScript
Mobile HTML, CSS, and JavaScript
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Building AngularJS Custom Directives
Building AngularJS Custom DirectivesBuilding AngularJS Custom Directives
Building AngularJS Custom Directives
 
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
 
Backbone js in action
Backbone js in actionBackbone js in action
Backbone js in action
 
Html5 and beyond the next generation of mobile web applications - Touch Tou...
Html5 and beyond   the next generation of mobile web applications - Touch Tou...Html5 and beyond   the next generation of mobile web applications - Touch Tou...
Html5 and beyond the next generation of mobile web applications - Touch Tou...
 
You Know WebOS
You Know WebOSYou Know WebOS
You Know WebOS
 

Destacado

Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
Pragnesh Vaghela
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
偉格 高
 

Destacado (18)

introduction to Marionette.js (jscafe14)
introduction to Marionette.js (jscafe14)introduction to Marionette.js (jscafe14)
introduction to Marionette.js (jscafe14)
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
Introduction à Marionette
Introduction à MarionetteIntroduction à Marionette
Introduction à Marionette
 
Intro to Backbone.js by Azat Mardanov for General Assembly
Intro to Backbone.js by Azat Mardanov for General AssemblyIntro to Backbone.js by Azat Mardanov for General Assembly
Intro to Backbone.js by Azat Mardanov for General Assembly
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ... Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
 
Introduction to Marionette Collective
Introduction to Marionette CollectiveIntroduction to Marionette Collective
Introduction to Marionette Collective
 
Marionette talk 2016
Marionette talk 2016Marionette talk 2016
Marionette talk 2016
 
Client-side MVC with Backbone.js
Client-side MVC with Backbone.js Client-side MVC with Backbone.js
Client-side MVC with Backbone.js
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Marionette Theater
Marionette TheaterMarionette Theater
Marionette Theater
 
RequireJS
RequireJSRequireJS
RequireJS
 
Introduction to Backbone.js
Introduction to Backbone.jsIntroduction to Backbone.js
Introduction to Backbone.js
 
RequireJS
RequireJSRequireJS
RequireJS
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 

Similar a Backbone/Marionette introduction

The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
Mark Fayngersh
 
Javascript spaghetti stirtrek_5_17
Javascript  spaghetti stirtrek_5_17Javascript  spaghetti stirtrek_5_17
Javascript spaghetti stirtrek_5_17
Jared Faris
 

Similar a Backbone/Marionette introduction (20)

Beyond rails new
Beyond rails newBeyond rails new
Beyond rails new
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
Professional JavaScript: AntiPatterns
Professional JavaScript: AntiPatternsProfessional JavaScript: AntiPatterns
Professional JavaScript: AntiPatterns
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 
The Next Five Years of Rails
The Next Five Years of RailsThe Next Five Years of Rails
The Next Five Years of Rails
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
Javascript spaghetti stirtrek_5_17
Javascript  spaghetti stirtrek_5_17Javascript  spaghetti stirtrek_5_17
Javascript spaghetti stirtrek_5_17
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application Platform
 
Top 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular AppTop 7 Angular Best Practices to Organize Your Angular App
Top 7 Angular Best Practices to Organize Your Angular App
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
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
panagenda
 

Último (20)

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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Backbone/Marionette introduction

  • 1. Let’s Learn Backbone.js building a re-usable table component
  • 2. Key things to keep in mind from the Throne of JS talk ✤ Clean code does not interleave concepts. Code that is around maintaining data should not be mixed with code messing with the DOM. ✤ DOM code should be focused, and not know about about other bits of DOM code. ✤ The source of truth should be in rich data structures, not embedded in the DOM.
  • 3. Components of Backbone.js ✤ The Model, an abstraction over a single REST resource ✤ The Collection, an abstraction over a REST collection of resources ✤ The View, a logical UI component ✤ The Router, a way to maintain application state
  • 4. The “real” pattern, MVP ✤ Backbone is MVP, Model View Presenter ✤ What backbone calls the view is actually the presenter, what it calls the template is actually the view ✤ This is confusing, but unimportant
  • 5. Model / Collection ✤ Where the data goes ✤ Emits events when things change ✤ When in doubt, push it down
  • 6. The View ✤ Operates on a single tree of elements ✤ Should never touch the html outside of its root element ✤ Should either be changing model/collection based on user interaction, or reacting to data changing ✤ Can be rendered without existing in the DOM ✤ Can be composed of multiple sub views
  • 7.
  • 8. The Router ✤ When you have a “single page” application, you often still want the back button to work, and users to have the ability to “deep link” ✤ The router accomplishes this via either tricks with hash marks, or with push state ✤ Least fundamental of all the components
  • 9.
  • 11. Backbone.Marionette ✤ Created by Derick Bailey, to provide structure in building larger javascript applications ✤ Philosophically very similar to backbone, just goes a few more steps ✤ Eliminates a lot of common boilerplate in backbone code by providing slightly higher level view abstractions ✤ Provides tools that become extremely useful when writing larger javascript applications
  • 12. Marionette Views ✤ Provides a additional convenience methods on top of what backbone gives you (ui hash, triggers hash, model events hash (added by me :) ✤ Provides a model binder, to prevent zombie views ✤ Frameworks away basic rendering code
  • 13. Marionette Views ✤ Item View, binds to a model ✤ Collection View, binds to a collection ✤ CompositeView, binds to a model and to a collection
  • 14. Marionette Tools ✤ Application Modules: Lets you group parts of the application, and start/stop them independently ✤ Layouts/Regions: Manage the creation/displaying/disposing of parts of the page which are dynamic ✤ Event Aggregator: Provides a module/application level event bus ✤ AppRouter: Routers that delegate to external objects
  • 16. CommonJS (in the asset pipeline) ✤ Using global scope is explicit ✤ You bring in a module with var Reference = require(“path/to/ module”) ✤ You choose what that Reference is by setting module.exports in the module ✤ You should never need to introduce a global variable ✤ Much nicer then ruby, but still behind a lot of other implementations (like python, clojure, scala, etc)
  • 17. Function.apply ✤ Inside a function, what “this” refers to is determined by the invocation ✤ If invoked off of an object, “this” will refer to that object ✤ If invoked in isolation, “this” will refer to the global scope ✤ If invoked via apply (or call), “this” is specified by the caller ✤ apply also lets you pass an array that will be used as arguments (you apply arguments to a function)
  • 18. Misc ✤ I have emacs set up to display function() as !(). This is purely cosmetic (it is still function when it saves) but I find it dramatically reduces the syntactic noise in the language.
  • 19. What are our requirements? ✤ Have a “new” row. It has a “create” button that when clicked, creates a resource on the server. When that resource is created, it creates a new row. ✤ Rows can be edited and deleted. ✤ Errors are shown, and edit boxes are highlighted ✤ There should be a way to override things at any level ✤ There should be a simple api for consumers to invoke

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n