Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Developing Backbone.js Applications
Prelude
1. Introduction
Fundamentals
MVC, MVP & Backbone.js
MVC
Smalltalk-80 MVC
MVC As We Know It
Models
Views
Controllers
Controllers in Spine.js vs Backbone.js
What does MVC give us?
Delving deeper
Summary
MVP
Models, Views & Presenters
MVP or MVC?
MVC, MVP and Backbone.js
Fast facts
Backbone.js
2. The Basics
What is Backbone?
Why should you consider using it?
The Basics
Models
Initialization
Getters & Setters
Model.set()
Views
Creating new views
What is el?
Collections
Underscore utility functions
Routers
Backbone.history
Namespacing
What is namespacing?
Additional Tips
Automated Backbone Scaffolding
Is there a limit to the number of routers I should be using?
Is Backbone too small for my application’s needs?
3. RESTful Applications
Building RESTful applications with Backbone
Stack 1: Building A Backbone App With Node.js, Express, Mongoose and MongoDB
Reviewing the stack
Practical
Practical Setup
MongoDB
Express and Mongoose
Building Backbone.js Apps With Ruby, Sinatra, MongoDB and Haml
Introduction
What Is Sinatra?
Getting Started With Sinatra
Routes
Redirection
Halting
Passing
Templating And HAML
ERB
Haml
MongoDB Ruby Driver
Getting started
Practical
Installing The Prerequisites
Ruby
Ruby Gems
Sinatra
Haml
MongoDB
1.Data directories
2.Running and connecting to your server
MongoDB Ruby Driver
Tutorial
Application Files
Backbone
Views
Collections
Model
Ruby/Sinatra
app.rb
Haml/Templates
index.haml
todo.haml
Conclusions
4. Advanced
Modular JavaScript
Organizing modules with RequireJS and AMD
Writing AMD modules with RequireJS
Alternate syntax
Keeping Your Templates External Using RequireJS And The Text Plugin
Optimizing Backbone apps for production with the RequireJS Optimizer
Practical: Building a modular Backbone app with AMD & RequireJS
Overview
Markup
Configuration options
Modularizing our models, views and collections
Decoupling Backbone with the Mediator and Facade patterns
Summary
Practical
Paginating Backbone.js Requests & Collections
Paginator’s pieces
Downloads And Source Code
Live Examples
Paginator.requestPager
1. Create a new Paginated collection
2: Set the model and base URL for the collection as normal
3. Map the attributes supported by your API (URL)
4. Configure the default pagination, query and sort details for the paginator
5. Finally, configure Collection.parse() and we’re done
Convenience methods:
Paginator.clientPager
1. Create a new paginated collection with a model and URL
2. Map the attributes supported by your API (URL)
3. Configure how to paginate data at a UI-level
4. Configure the rest of the request parameter default values
5. Finally, configure Collection.parse() and we’re done
Convenience methods:
Views/Templates
Backbone & jQuery Mobile
Resolving the routing conflicts
Practical: A Backbone, RequireJS/AMD app with jQuery Mobile
Getting started
jQuery Mobile: Going beyond mobile application development
5. Unit Testing
Unit Testing Backbone Applications With Jasmine
Introduction
Jasmine
Suites, Specs & Spies
beforeEach and afterEach()
Shared scope
Getting setup
TDD With Backbone
Models
Collections
Views
Initial setup
View rendering
Rendering with a templating system
Conclusions
Exercise
Further reading
Unit Testing Backbone Applications With QUnit And SinonJS
Introduction
QUnit
Getting Setup
Sample HTML with QUnit-compatible markup:
Assertions
Basic test case using test( name, callback ):
Comparing the actual output of a function against the expected output:
Adding structure to assertions
Basic QUnit Modules:
Using setup() and teardown() :
Using setup() and teardown() for instantiation and clean-up:
Assertion examples
equal - a comparison assertion. It passes if actual == expected
notEqual - a comparison assertion. It passes if actual != expected
strictEqual - a comparison assertion. It passes if actual === expected.
notStrictEqual - a comparison assertion. It passes if actual !== expected.
deepEqual - a recursive comparison assertion. Unlike strictEqual(), it works on objects, arrays and primitives.
notDeepEqual - a comparison assertion. This returns the opposite of deepEqual
raises - an assertion which tests if a callback throws any exceptions
Fixtures
Fixture markup:
Fixtures example:
Asynchronous code
SinonJS
What is SinonJS?
Basic Spies:
Spying On Existing Functions:
Matching arguments: test a spy was called with a specific set of arguments:
Stricter argument matching: test a spy was called at least once with specific arguments and no others:
Testing call order: testing if a spy was called before or after another spy:
Match execution counts: test a spy was called a specific number of times:
Stubs and mocks
Stubs
Mocks
Practical
Models
Collections
Views
Events
App
Further Reading & Resources
6. Resources
7. Conclusions
About the Author
← Prev
Back
Next →
← Prev
Back
Next →