npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

central

v0.1.3

Published

An isomorphic module project based on Backbone.js

Downloads

48

Readme

central.js

A Backbone-based javascript isomorphic framework


Install

$ npm install -g central

Usage

Bootstrap an app

$ central app_name
$ npm install
$ grunt

Use directly

var central = require('central'),
    server = central.createServer();

server.configure({
    routes: routes,
    staticFolder: __dirname + '/public',
    controller: new Controller(),
    rootEl: '.content'
});

server.start();

Documentation

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.

Controller

The main piece of logic in a central.js application is the Controller. Shared in both client and server, the Controller is what brings together Backbone Views, Backbone Models and routing. The 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')

class MyController extends BaseController

    route1: @::view(MyView) (params) ->
        myModel = new MyModel(name: 'Tom', age: 18)
        return model: myModel

    route2: @::viewWithCallback(MyView) (params, callback) ->
        myModel = new MyModel()
        myModel.fetch
            success: ->
                // do stuff
                callback(model: myModel)
            error: ->
                // do error stuff
                callback(model: myModel)

In this example, whenever the user hits route1, the Controller will instantiate MyModel and pass it to the MyView view. route1 uses the ::view() decorator which tells the Controller what Backbone.View it should use.

For route2, the 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.

Launching the app

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 = require('central'),
    routes = require('./app/routes'),
    Controller = require('./app/controller.coffee'),
    server = central.createServer();

server.configure({
    routes: routes,
    staticFolder: __dirname + '/public' // path to the static folder
    controller: new Controller(),
    rootEl: '.content' // CSS selector in the layout file where you want to render your views
});

server.start();

and then

$ 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 = require('central'),
    express = require('express'),
    app = express(),
    server = central.createServer();

server.configure({
    // Configuration
});

app.use(server.expressApp);

app.listen(3030);

License

MIT © Arthur Himmel