Classes

RouterReducerWrapper

Typedefs

Resolver : function
Middleware : string | Resolver | RegExp | Router

flow control statement or function

 

Router ⇐ ReducerWrapper

Kind: global class
Extends: ReducerWrapper

 

new Router()

Cascading router

 

router.use(...resolvers) ⇒ Object

Appends middleware, action handler or another router

Kind: instance method of Router
Params

Example

// middleware
router.use((req, res, postBack) => Router.CONTINUE);

// route with matching regexp
router.use(/help/, (req, res) => {
    res.text('Hello!');
});

// route with matching function (the function is considered as matcher
// in case of the function accepts zero or one argument)
router.use('action', req => req.text() === 'a', (req, res) => {
    res.text('Hello!');
});

// use multiple reducers
router.use('/path', reducer1, reducer2)
   .onExit('exitAction', (data, req, res, postBack) => {
       postBack('anotherAction', { someData: true })
   });

// append router with exit action
router.use('/path', subRouter)
   .onExit('exitAction', (data, req, res, postBack) => {
       postBack('anotherAction', { someData: true })
   });
 

Router.CONTINUE

Return Router.CONTINUE when action matches your route Its same as returning true

Kind: static property of Router
Properties

Type
boolean
 

Router.BREAK

Return Router.BREAK when action does not match your route Its same as returning false

Kind: static property of Router
Properties

Type
boolean
 

Router.END

Returning Router.END constant stops dispatching request Its same as returning undefined

Kind: static property of Router
Properties

Type
null
 

Router.exit(action, [data]) ⇒ Array

Create the exit point Its same as returning ['action', { data }]

Kind: static method of Router
Params

  • action string - the exit action
  • [data] Object - the data

Example

router.use((req, res) => {
    return Router.exit('exitName');
});
 

Resolver : function

Kind: global typedef
Params

  • [req] Request
  • [res] Responder
  • [postBack] function
 

Middleware : string | Resolver | RegExp | Router

flow control statement or function

Kind: global typedef

results matching ""

    No results matching ""