
http://ricostacruz.com/backbone-patterns/
Testing Backbone applications with Jasmine and Sinon – Part 3. Routers and Views – Tinned Fruit Overview This is the third and final part in a series of articles demonstrating how to test a Backbone.js application, employing the Jasmine BDD test framework and the Sinon.JS spying, stubbing and mocking library If you haven’t yet read the first or second parts, take a look now. In this final part, we’ll be looking at some methods for unit testing Backbone routers and views. These object types both present their own unique challenges for testing, but and provide the tools we need to isolate them and fake external code and system dependencies. We will be examining the following: different approaches to testing Backbone routes Build a Contacts Manager Using Backbone.js: Part 4 In part four of this series, we saw how easy it is to add and remove models from our collection, and keep the page updated in sync with the changes. In this part, we're going to look at editing existing model data. Getting Started
Efficient model memcaching Posted by Nick Johnson | Filed under tech, app-engine, cookbook, coding This is the first in a series of 'cookbook' posts describing useful strategies and functionality for writing better App Engine applications. One common pattern in App Engine is using memcache to store entities retrieved from the datastore - either individual ones or a list of them - to avoid re-executing common queries. The natural pattern is something like this: JavaScript Garden Although JavaScript deals fine with the syntax of two matching curly braces for blocks, it does not support block scope; hence, all that is left in the language is function scope. function test() { // a scope for(var i = 0; i < 10; i++) { // not a scope // count } console.log(i); // 10} There are also no distinct namespaces in JavaScript, which means that everything gets defined in one globally shared namespace.
Sample App with Backbone.js and Twitter Bootstrap Backbone.js is a lightweight JavaScript framework that provides the basic infrastructure (Model, Collection, View, and Router classes) to bring structure to your Web applications. Twitter Bootstrap is a UI toolkit that provides simple and flexible HTML, CSS, and Javascript to implement popular user interface components and interactions. In other words, Backbone.js and Twitter Bootstrap focus on different areas of your application: core architecture and user interface respectively. Because of their well-defined and non-overlapping scope, Backbone.js and Twitter Bootstrap work well together.
Ja.mesBrown JavaScript and Web Development If you are developing web applications that utilize Ajax (and most do today) and are using jQuery and/or Backbone.js, you should be building with mock Ajax JSON responses. You can view the code on Github: or the examples: Servers are slow / Rapid Iteration When developing against a local server, the ajax response will typically 100-300 milliseconds, but could even be longer. Michi Kono » Blog Archive » Adding a Centralized Event Dispatcher on Backbone.js This article contains my solution to adding a simple global event dispatcher to Backbone. It should also help noobies (myself included) understand how Backbone events work (which has one big gotcha). Sharing Events = Global Dispatcher Today, I came across a fairly mundane – and probably common – problem: I have two views that need to talk to each other. An example for this would be when you have a status bar in one corner that gets updated when a user completes an action in another area. It turns out that Backbone (as far as I can tell) does not support this use case very well out of the box.
Zombies! RUN! (Managing Page Transitions In Backbone Apps) One of the common issues or questions I see for Backbone.js goes something like this: “Whenever I hit the same route more than once, I end up getting seeing this call being made multiple times. It seems to accumulate another call every time I hit the route. What’s going on?” or “I’ve noticed that my views are still handling events after I remove them from the screen. References, Routing, And The Event Aggregator: Coordinating Views In Backbone.js I recently found myself needing to facilitate communication between two backbone views. The first view is a medication – one that is currently being taken by a particular patient. The second view is the add/edit view that allows the patient to either add new medications or edit existing ones. When the edit icon is clicked for an existing medication, the edit form should be populated and the user should be able to edit the medication. Here’s what the screen looks like after I click on the edit icon (the pencil): There are a number of ways to make this work – the most basic of which is to have the views reference each other so that they can either call methods on each other or raise events.
Organizing Your Backbonejs Application With Modules If you have spent any time looking at Backbone.js, like many others, you are probably amazed by how lightweight, flexible and elegant it is. Backbone.js is incredibly powerful, but not prescriptive in how it should be used. With great power comes great responsibility, and if you’ve tried to use Backbone.js for a large project you might be asking yourself: how do I organize my code? When thinking about “code organization” the questions you might be asking are: Auto-Save User's Input In Your Forms With HTML5 and Sisyphus.js Advertisement This article is the third in our new series that introduces new, useful and freely available tools and techniques, developed and released by active members of the Web design community. The first article covered PrefixFree; the second introduced Foundation, a responsive framework that helps you build prototypes and production code. This time, we’re presenting Sisyphus.js, a library developed by Alexander Kaupanin to provide Gmail-like client-side drafts and a bit more. What Problem Needs Solving? Have you ever been filling out a long form online or writing an eloquent and spirited comment when suddenly the browser crashes?
Simplify.js - a high-performance JavaScript 2D/3D polyline simplification library Simplify.js (License: BSD, GitHub: mourner / simplify-js, npm: simplify-js) is a tiny high-performance JavaScript polyline simplification library by Vladimir Agafonkin, extracted from Leaflet, a JS interactive maps library of the same author. It uses a combination of Douglas-Peucker and Radial Distance algorithms. Works both on browser and server platforms. Polyline simplification dramatically reduces the number of points in a polyline while retaining its shape, giving a huge performance boost when processing it and also reducing visual noise. For example, it's essential when rendering a 70k-points line chart or a map route in the browser using Canvas or SVG. 73752 points, simplified with tolerance: 0.8 px After simplification: 154 points (~479 times less) Performed in 2.73 ms
JavaScript Architecture: Backbone.js Routers Updated Aug 11, 2012 to reflect current library versions. In JavaScript Architecture: Backbone.js Views we discussed how to build dynamic apps that change views on the fly using JavaScript. Because view-switching is done without reloading the page or transferring control to a separate page, these are called single-page applications. Single-page applications pose a few issues we need to address: