SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Dummies
       ne.js      for
Backb o               backbon e wi t h
        uction to use
I ntrod           s 3.1.x
              Rail
Everybody
needs an intro
course, Right?
3 Reasons to Use a
Front End Framework?
1. It Makes Your Front-
   End Code Testable
2. It Makes Your Front-
   End Code Testable
3. It Makes Your Front-
   End Code Testable
Jasmine.js
Other Benefits
•   Responsive UI with Event-Driven Communication

•   Maintainable Client Side Code by Convention

•   Easy Client-Server Syncing (RESTful)

•   Easy to integrate Web-Socket Technology

•   Works very well together with the Rails Asset
    Pipeline
The Rails Way
• Have you ever felt limited by Rail’s way to
  structure your App around resources and
  the RESTful actions. Do you design your
  Rails app in such a way (scaffoldish) that its
  easy and cheap to develop?
• Would you like to do what-ever you want
  on the front-end, but still use a restful, well
  structured, testable back-end?
Example App
Demo:
Have a look at the App
http://documentcloud.github.com/backbone/
Learning Backbone.js
This presentation is not a course, there are many
catches, do some good training, it will help you.

    •   Sources:

        •   Peepcode.com has 3 very good screencasts.
            http://peepcode.com/products/backbone-js

        •   Thoughtbot has a very good book:
            https://workshops.thoughtbot.com/
            backbone-js-on-rails
Cookbook
• Rails 3.1.3
• Backbone.js
• JQuery
• Pusher
• EJS Templates
• Backbone Forms
Backbone.js

• Model,View, Router
• Lightweight (< 700 lines)
• No UI Widgets - Write your own html,
  erb, haml, css, scss, sass
• Template Agnostic, bring your own
Use
www.coffeescript.org
Use a Push Technology

• Faye - http://faye.jcoglan.com/
• Event Machine - http://
  rubyeventmachine.com/
• Pusher
www.pusher.com
Pusher
•   It’s a complete abstraction of Push Technology in a SAAS
    approach

•   How does it work?

    •   Backend App send posts to Pusher server (Pusher
        GEM)

    •   Front-End uses Javascript to receive the events

    •   Channel based

    •   Uses web-sockets and falls back to Flash
jquery / zepto and
           Backbone.js
•   JQuery / Zepty: mark-up oriented

•   Backbone.js:

    •   Data Oriented
        Manipulate data and views are updated
        automatically.

    •   Single Page Application. Router ensures that
        the correct data is shown.

•   You need Both!
Templates

• .jst Templates (ejs) - http://embeddedjs.com
• The templates are rendered and then
  enriched with data by JQuery or Zepto
• Backbone-Forms - https://github.com/
  powmedia/backbone-forms
Example App: Shopping
      List App
Application Structure
• Details are free to chose - here a proposal
  is given - some people organise differently
• All Front End Code goes into
 • app/assets/javascripts
 • lib/assets/javascripts
 • vendor/assets/javascripts
Application Structure
            Collections

              Models
             Routers

              App

              Views
RSpec - Jasmine
  Structure
App
Not part of Backbone as such...
Used to have a namespace in JavaScript and
to avoid the information hiding problems of
JavaScript
App Specs
App Implementation
Models
Basic data structure used to capture behavior
of single instances. Instance methods,
abstraction sever interaction: save, destroy.
Model Spec
Models
Usage of Models
Collections
Data stucture to manage sets of instances.
Methods for filtering, sorting, abstraction of
server interaction: fetch.
Fixtures
Collection Specs
Collection
Views

• Used to view and interact with data
 • More comparable with a Rails controller
    than a Rails view.
 • Binds to Models and Collections to re-
    render itself when required.
Views, subviews
               ShoppingItemItem




     ShoppingItemsIndex
Templates
Templates
Combined Approach
View Specs
View
https://github.com/powmedia/backbone-forms

      Backbone Forms
One of the many form options.
Specify a schema in the model and generate a
shema from that model.
Use “commit” to save the form changes in your
model.
Save the model to the server.
Backbone Forms
Router
• Used to structure the various pages of
  your application.
• Translates URLs into the rendering of the
  correct views.
• Updates the browser URL and history.
• Option to use “#” or “/” as URL delimiter.
Router
Test
Kind of Tests?
•   Rails                     •   Backbone.js

    •   Acceptance Tests:         •   App Specs
        Capybara, Rspec
        Request, Cucumber
        with Selenium & Co.
                                  •   Helper Specs

                                  •   Models &
    •   Model Tests (rspec,           Collections Specs
        test Unit, ...)
                                  •   Router & Views
                                      Specs
Sync Adaptations
•   csrf:
    You need a
    BackboneRailsAuthTokenAdapter.
    I use the one of Thoughtbot.

•   Pusher
    You need to adapt the sync method to respond on
    incomming web-socket connections.
    I use the BackPusher, but there some bugs in it
    that you need to repair (due to newer backbone
    version) to pass the web-socket-id as a parameter.
Putting in Place Pusher


• Push State via Controler Adaptations
• Use BackPusher
Pusher - Rails Initializers
Pusher - Rails Controller
Pusher In App
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
Anton Narusberg
 
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JSJavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
Harbinger Systems - HRTech Builder of Choice
 

Was ist angesagt? (20)

Rails engines
Rails enginesRails engines
Rails engines
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
 
Spring.new hope.1.3
Spring.new hope.1.3Spring.new hope.1.3
Spring.new hope.1.3
 
Namespace less engine
Namespace less engineNamespace less engine
Namespace less engine
 
Angular.JS: Do it right
Angular.JS: Do it rightAngular.JS: Do it right
Angular.JS: Do it right
 
Rails 3.1 Asset pipeline
Rails 3.1 Asset pipelineRails 3.1 Asset pipeline
Rails 3.1 Asset pipeline
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Creating ambitious web application with Ember.js
Creating ambitious web application with Ember.jsCreating ambitious web application with Ember.js
Creating ambitious web application with Ember.js
 
RESTful Api practices Rails 3
RESTful Api practices Rails 3RESTful Api practices Rails 3
RESTful Api practices Rails 3
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesKeep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
 
Production ember getting started
Production ember getting startedProduction ember getting started
Production ember getting started
 
React on rails v4
React on rails v4React on rails v4
React on rails v4
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
 
Real World Rails Deployment
Real World Rails DeploymentReal World Rails Deployment
Real World Rails Deployment
 
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JSJavaScript MVC Frameworks: Backbone, Ember and Angular JS
JavaScript MVC Frameworks: Backbone, Ember and Angular JS
 
Session iv(master pages)
Session iv(master pages)Session iv(master pages)
Session iv(master pages)
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 

Andere mochten auch (8)

Adiquity Publisher
Adiquity PublisherAdiquity Publisher
Adiquity Publisher
 
Adiquity Premium Offering
Adiquity Premium OfferingAdiquity Premium Offering
Adiquity Premium Offering
 
123團購網 new
123團購網 new123團購網 new
123團購網 new
 
Prototipo
PrototipoPrototipo
Prototipo
 
King louis xvi
King louis xviKing louis xvi
King louis xvi
 
Prototipo Pantalla Touch
Prototipo Pantalla TouchPrototipo Pantalla Touch
Prototipo Pantalla Touch
 
MI
MIMI
MI
 
Photo album 1
Photo album 1Photo album 1
Photo album 1
 

Ähnlich wie Backbonification for dummies - Arrrrug 10/1/2012

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
tboyt
 
Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0
Mayank Srivastava
 

Ähnlich wie Backbonification for dummies - Arrrrug 10/1/2012 (20)

Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Introduction to Ember.js and how we used it at FlowPro.io
Introduction to Ember.js and how we used it at FlowPro.ioIntroduction to Ember.js and how we used it at FlowPro.io
Introduction to Ember.js and how we used it at FlowPro.io
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
Show Some Spine!
Show Some Spine!Show Some Spine!
Show Some Spine!
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Remix
RemixRemix
Remix
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
 
PLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring SurfPLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
 
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
 
Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Isomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the webIsomorphic JavaScript – future of the web
Isomorphic JavaScript – future of the web
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
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...
 
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?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 

Backbonification for dummies - Arrrrug 10/1/2012

  • 1. Dummies ne.js for Backb o backbon e wi t h uction to use I ntrod s 3.1.x Rail
  • 3. 3 Reasons to Use a Front End Framework?
  • 4. 1. It Makes Your Front- End Code Testable
  • 5. 2. It Makes Your Front- End Code Testable
  • 6. 3. It Makes Your Front- End Code Testable
  • 8. Other Benefits • Responsive UI with Event-Driven Communication • Maintainable Client Side Code by Convention • Easy Client-Server Syncing (RESTful) • Easy to integrate Web-Socket Technology • Works very well together with the Rails Asset Pipeline
  • 9. The Rails Way • Have you ever felt limited by Rail’s way to structure your App around resources and the RESTful actions. Do you design your Rails app in such a way (scaffoldish) that its easy and cheap to develop? • Would you like to do what-ever you want on the front-end, but still use a restful, well structured, testable back-end?
  • 11. Demo: Have a look at the App
  • 13. Learning Backbone.js This presentation is not a course, there are many catches, do some good training, it will help you. • Sources: • Peepcode.com has 3 very good screencasts. http://peepcode.com/products/backbone-js • Thoughtbot has a very good book: https://workshops.thoughtbot.com/ backbone-js-on-rails
  • 14. Cookbook • Rails 3.1.3 • Backbone.js • JQuery • Pusher • EJS Templates • Backbone Forms
  • 15. Backbone.js • Model,View, Router • Lightweight (< 700 lines) • No UI Widgets - Write your own html, erb, haml, css, scss, sass • Template Agnostic, bring your own
  • 16. Use
  • 18. Use a Push Technology • Faye - http://faye.jcoglan.com/ • Event Machine - http:// rubyeventmachine.com/ • Pusher
  • 20. Pusher • It’s a complete abstraction of Push Technology in a SAAS approach • How does it work? • Backend App send posts to Pusher server (Pusher GEM) • Front-End uses Javascript to receive the events • Channel based • Uses web-sockets and falls back to Flash
  • 21. jquery / zepto and Backbone.js • JQuery / Zepty: mark-up oriented • Backbone.js: • Data Oriented Manipulate data and views are updated automatically. • Single Page Application. Router ensures that the correct data is shown. • You need Both!
  • 22. Templates • .jst Templates (ejs) - http://embeddedjs.com • The templates are rendered and then enriched with data by JQuery or Zepto • Backbone-Forms - https://github.com/ powmedia/backbone-forms
  • 24. Application Structure • Details are free to chose - here a proposal is given - some people organise differently • All Front End Code goes into • app/assets/javascripts • lib/assets/javascripts • vendor/assets/javascripts
  • 25. Application Structure Collections Models Routers App Views
  • 26. RSpec - Jasmine Structure
  • 27. App Not part of Backbone as such... Used to have a namespace in JavaScript and to avoid the information hiding problems of JavaScript
  • 30. Models Basic data structure used to capture behavior of single instances. Instance methods, abstraction sever interaction: save, destroy.
  • 34. Collections Data stucture to manage sets of instances. Methods for filtering, sorting, abstraction of server interaction: fetch.
  • 38. Views • Used to view and interact with data • More comparable with a Rails controller than a Rails view. • Binds to Models and Collections to re- render itself when required.
  • 39. Views, subviews ShoppingItemItem ShoppingItemsIndex
  • 44. View
  • 45. https://github.com/powmedia/backbone-forms Backbone Forms One of the many form options. Specify a schema in the model and generate a shema from that model. Use “commit” to save the form changes in your model. Save the model to the server.
  • 46.
  • 48. Router • Used to structure the various pages of your application. • Translates URLs into the rendering of the correct views. • Updates the browser URL and history. • Option to use “#” or “/” as URL delimiter.
  • 50. Test
  • 51. Kind of Tests? • Rails • Backbone.js • Acceptance Tests: • App Specs Capybara, Rspec Request, Cucumber with Selenium & Co. • Helper Specs • Models & • Model Tests (rspec, Collections Specs test Unit, ...) • Router & Views Specs
  • 52. Sync Adaptations • csrf: You need a BackboneRailsAuthTokenAdapter. I use the one of Thoughtbot. • Pusher You need to adapt the sync method to respond on incomming web-socket connections. I use the BackPusher, but there some bugs in it that you need to repair (due to newer backbone version) to pass the web-socket-id as a parameter.
  • 53. Putting in Place Pusher • Push State via Controler Adaptations • Use BackPusher
  • 54. Pusher - Rails Initializers
  • 55. Pusher - Rails Controller

Hinweis der Redaktion

  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
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n