@superhero/router

0.5.6 • Public • Published

Router

Licence: MIT


npm version

A router that offers an hierarchy of dispatchers to an event bus.

Install

npm install @superhero/router

...or just set the dependency in your package.json file:

{
  "dependencies":
  {
    "@superhero/router": "*"
  }
}

Example

const
EventBus  = require('events');
bus       = new EventBus(),
debugging = true,
routes    =
[
  {
    name        :  'authentication',
    dispatchers : ['api/authentication']
  },
  {
    name        :  'authorization',
    dispatchers : ['api/authorization']
  },
  {
    name        :  'unauthorize',
    dispatchers : ['api/unauthorize']
  },
  {
    dispatchers : ['api/authorize'],
    children    :
    [
      {
        name        :  'foo',
        dispatchers : ['api/foo']
      },
      {
        name        :  'bar',
        acl         : ['admin','editor'], // optional acl validation, will
                                          // validate to first object sent as
                                          // parameter through the member
                                          // variable "role"
        dispatchers : ['api/bar']
      }
    ]
  }
];

require('@superhero/router')(bus, routes, debugging);

A dispatcher can break the dispatcher loop by throwing an object with the attributes name and context, which will be triggered as an event, or throw "nothing" (eg: false, 0, undefined...).

Package Sidebar

Install

npm i @superhero/router

Weekly Downloads

4

Version

0.5.6

License

MIT

Last publish

Collaborators

  • superhero