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

js-backbone-router-handler

v1.0.6

Published

Router and Controller handling by config for backbone router.

Downloads

1

Readme

backbone-router-handler

General

This router handler provides a more flexible way for routing in combination with Controller. This router handler inherits from the BackBone.Router.

Install

bower install backbone-router-handler --save
npm install js-backbone-router-handler --save

Example

function ControllerTest() {
    Controller.apply(this, arguments);
}

ControllerTest.prototype = Object.create(Controller.prototype);

ControllerTest.prototype.home = function() {
    // do home controller stuff for route /home
};

ControllerTest.prototype.bundles = function() {
    // do home controller stuff for route /bundles
};

ControllerTest.prototype.bundle = function(id) {
    // do home controller stuff for route /bundle/:id
};

ControllerTest.prototype.bundleEditNuff = function(id) {
    // do home controller stuff for route /bundle/edit/nuff/:id
};

ControllerTest.prototype.keks = function() {
    // do home controller stuff for route /keks
};

let router = new Router([
    {
        // can be the controller constructor or a instance of a controller
        controller: ControllerTest,

        // defines all route for this controller. A route entry can be a string or
        // an object with detailed informations
        // every entry can also be an string. they will be converted to object
        routes: [
            {
                // defines this route as the default route. This key can only be once TRUE in the whole config
                // this property is optional
                isDefault: true,

                // defines a route
                // @see http://backbonejs.org/#Router-routes
                route: 'home',

                // defines the name of the route. This property is optional.
                // @see http://backbonejs.org/#Router-routes
                name: 'homeRoute',

                // defines the parts of a route without parameters. This property is optional.
                // this property will be use in the internal dispatcher of the controller
                // normaly this property should not be defined and will be generated if not defined.
                // the parts will be generated from the route.
                // @see forge/backbone/controller.js
                // @example "bundle/edit/nuff/:id" will be [bundle, edit, nuff]
                // @example parts is string with "bundle/edit/nuff": will be [bundle, edit, nuff]
                parts: []
            },

            // defines only a route without detailed informations
            'bundles',

            // defines only a route without detailed informations
            'bundle/:id',

            // defines only a route without detailed informations
            'bundle/edit/nuff/:id',

            // defines only a route without detailed informations
            'keks'
        ]
    },

    // defines more route with other controllers
    {
        // controllers and routes definitions here
    }
]);

If the router detect the route

  • /home then the controller action ControllerTest.prototype.home
  • /bundles then the controller action ControllerTest.prototype.bundles
  • /bundle/42 then the controller action ControllerTest.prototype.bundle with the parameter 42
  • /bundle/edit/nuff/10 then the controller action ControllerTest.prototype.bundleEditNuff with the parameter 10
  • /keks then the controller action ControllerTest.prototype.keks

If the router detect a controller switch, the function "removeView" of the previous controller will be called.

Every controller will only be instantiated once.

The controllers must inherit from Controller.

getDefaultRoutePath

The router provides the function "getDefaultRoutePath", which returns the default route string. This make it easy to get and navigate to the default route.