Book Image

Building Scalable Apps with Redis and Node.js

By : Joshua Johanan
Book Image

Building Scalable Apps with Redis and Node.js

By: Joshua Johanan

Overview of this book

Table of Contents (17 chapters)
Building Scalable Apps with Redis and Node.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Backbone models


We have just built all the views and a few of them referenced models and collections, which is why we will create all the required objects right now. The first thing we need to do is create a file named models.js under static/js/. This will be the file that holds all the definitions for our models, collections, and router.

Syncing the models with Socket.IO

Backbone models and collections are built to work within a REST framework. Each Backbone model and collection has a sync method that maps the four CRUD operations (Create, Read, Update, and Delete) to a URL that we would pass in. Our application does not use REST to transfer data from the server to client; it uses Socket.IO. There is no built-in adapter, so we must roll our own. We will break down this object into a couple of pieces. The following code is the first piece:

var SocketListener = function SocketListener(noun, collection, socket){
  var addModels = function addModels(models){
      collection.add(collection.parse...