An isomorphic module project based on Backbone.js
$ npm install -g central
$ central app_name$ npm install$ grunt
var central =server = central;server;serverstart;
central.js was built around the famous Backbone.js and highly depends on it. If you are not (yet) familiar with Backbone, it may be better to go and read its documentation first.
The main piece of logic in a central.js application is the
Shared in both client and server, the
Controller is what brings together Backbone Views, Backbone Models and routing.
Controller works tightly with the
routes.js file, which usually takes this form :
module.exports =path: '/route1'view: 'route1'path: '/route2'view: 'route2'
A central.js controller typically looks like this :
BaseController = require'central/shared/controller.coffee'MyView = require'../views/my_view.coffee'MyModel = require'../models/my_model.coffee'route1: @::viewMyViewmyModel = name: 'Tom'age: 18return model: myModelroute2: @::viewWithCallbackMyViewmyModel =myModelfetch: ->// do stuffcallbackmodel: myModel: ->// do error stuffcallbackmodel: myModel
In this example, whenever the user hits
Controller will instantiate
MyModel and pass it to the
route1 uses the
::view() decorator which tells the
Backbone.View it should use.
Controller first instantiate a model and requests some data from the database. The
@::viewWithCallback decorator allows the controller to wait for the database results before rendering the view, which is only triggered when
callback is called.
The syntax of the
Controller is the only thing that is imposed when developing an isomorphic application with central.js. Pretty much everything else will look like a regular Backbone.js client-side application.
central.js uses an instance of express.js, which is a server-side server based on node.js, to handle responses. You can use this instance as your primary server, or just to handle your Backbone.js isomorphic application.
To launch the server, you only need a
index.js file where you will basically put :
var central =routes =Controller =server = central;server;serverstart;
$ node index.js
You also can integrate the central.js app into your existing express.js server, by using it as a middleware :
var central =express =app =server = central;server;app;app;
MIT © Arthur Himmel