Single Page Application
     Development with
backbone.js and Simple.Web
          Chris Canal
Who am I?
•   Senior Developer at StormID
•   Developed our in-house SDK
•   Does too much Umbraco
•   Trying to stop my boss from crazy
•   Being opinionated
•   Been doing this for too long, 11 years!
•   Crap at making PowerPoint presentations
•   Probably wrong 90% of the time, so
    please correct me when I made a stupid
    comment
Agenda
• Introduction
• Backbone
   •   Backbone Marionette
   •   Underscore
   •   Handlebars
   •   RequireJS
• Simple.Web
Single Page Applications
Single Page Application?
• A software application
• On a single web page
• Pretty much exactly what it says on the tin, if it came in a tin
Gmail
mail.google.com
Twitter
twitter.com
Facebook
facebook.com
Spin
spin.com
A Quick Web App History
Web 1.0

          GET

                Webserver
Web 1.0
          GET




          GET   Webserver
AJAX, BOOYA
AJAX (Web 2.0?)
                  GET




                  GET   Webserver
AJAX (Web 2.0?)
                  GET




                  GET   Webserver
AJAX (Web 2.0?)
                  GET




                  GET   API
  Application
MV*
MV*
• MVPresenter
• MVController
• MVPresentationModel
• MVViewModel
• MVHandler
Serverside MV*
Small Talk
First implentation of MVC
Ruby on Rails
MVC
Cake PHP
MVC
WebForms
Wut?
Castle Monorail
MVC
ASP.NET MVC
MVC
FubuMVC
MVC
Simple.Web
MVHandler
Simple.Web
Conventions &
Structure
Clientside MV*
YUI
Ember JS
Knockout
AngularJS
Backbone.js
Backbone.js
What is it?
• Event driven MV* Framework
Annotated Source
Github
Who uses Backbone.js?
• Hulu
• Foursquare
• Stripe
• Khan Academy
• Wordpress.com
• Many more…
Code Structure
• Events
• Models
• Collections
• Views
• Router
Events
on
off
trigger
on
off
trigger
Beware memory leaks!
Event Types
• add – model, collection
• remove – model, collection
• reset – collection
• change – model, options
• change:[attribute] – model, value, options
• destroy – model, collection
• sync – model, collection
• route:[name] – router
• all
Models
extend
constructor/initialize
url/urlRoot
defaults
get/set
validate
toJSON
State!
save
and more…
extend
extend
Overriding base methods
constructor/initialize
initialize
url/urlRoot
defaults
get/set
validate
toJSON
State!
save
More!
Collections
model
url
create
add
get
where
fetch
reset
and more…
model
url
create
add
get
where
fetch
reset
More!
Views
el/tagName/$el
render
remove
events
el/tagName/$el
render
remove
events
router
routes
Route
navigate
History
routes
route
navigate
Demo?
Questions?
Backbone Marionette
What is it?
Application Library for Backbone
What does it give you?
• Backbone.Marionette.Application
• Backbone.Marionette.AppRouter
• Backbone.Marionette.ItemView
• Backbone.Marionette.CollectionView
• Backbone.Marionette.EventAggregator
• And more…
Backbone.Marionet
te.Application
Starting An Application
events
addInitializer
regions
Starting
events
addInitializer
regions
Backbone.Marionet
te.AppRouter
controller
controller
Backbone.Marionett
e.ItemView
on*
events
serializeData
On*
events
serializeData
Backbone.Marionett
e.CollectionView
itemView
emptyView
on*
events
itemView
emptyView
on*
events
Backbone.Marionett
e.EventAggregator
Demo?
Questions?
Underscore
What is it?
Batman utility belt
Handlebars
What is it?
Mustache templating implemetation
Basic
Compiling
Using it with Backbone.Marionette
RequireJS
What is it?
Clientside Dependency Management
AMD/CommonJS implentation
What does it give you?
• Dependency Management
Config
Config
require()
define()
Text plugin
Using it with Backbone.Marionette
r.js
What is it?
• Combines related scripts together into build layers and minifies them
  via UglifyJS
• Optimizes CSS by inlining CSS files referenced by @import and
  removing comments.
Getting it…
• You have Node.js installed, yea?
• npm install –g requires
• node r.js path/tp/buildscript.js
Config
Config
Demo?
Questions?
Simple.Web
What is it?
SOLID Driven RESTful web framework
Model-View-Hander
What does it give you?
• Proper Separation on Concerns – One class per action
• Easily Testable
• SOLID Compliant
Interfaces
• IGet
• IPost
• IPost<T>
• IDelete
• IPut
• IPut<T>
• IOutput
• And more…
IGet
IPost
IPost<T>
IDelete
IPut<T>
IOutput<T>
Demo
Wiring it all up!
Questions?
Resources
• http://backbonetraining.net/resources Loads of Backbone resources
• https://github.com/markrendle/Simple.Web
• http://blog.markrendle.net/2012/06/01/simple-web/
Thanks!

Single Page Application Development with backbone.js and Simple.Web

Editor's Notes

  • #41 Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions,views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.When working on a web application that involves a lot of JavaScript, one of the first things you learn is to stop tying your data to the DOM. It&apos;s all too easy to create JavaScript applications that end up as tangled piles of jQuery selectors and callbacks, all trying frantically to keep data in sync between the HTML UI, your JavaScript logic, and the database on your server. For rich client-side applications, a more structured approach is often helpful.With Backbone, you represent your data as Models, which can be created, validated, destroyed, and saved to the server. Whenever a UI action causes an attribute of a model to change, the model triggers a &quot;change&quot; event; all the Views that display the model&apos;s state can be notified of the change, so that they are able to respond accordingly, re-rendering themselves with the new information. In a finished Backbone app, you don&apos;t have to write the glue code that looks into the DOM to find an element with a specific id, and update the HTML manually — when the model changes, the views simply update themselves.
  • #122 Loading text documents as dependencies