Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

base-router

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-router - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

31

index.js

@@ -5,3 +5,3 @@ module.exports = Router

var inherits = require('inherits')
var createRouter = require('routes')
var createRouter = require('routington')

@@ -17,3 +17,3 @@ function Router (routes, opts) {

Object.keys(routes).forEach(function BaseRouter_forEachRoutes (key) {
self.route(key, routes[key])
self.addRoute(key, routes[key])
})

@@ -25,7 +25,14 @@ }

Router.prototype.addRoute = function BaseRouter_addRoute (name, model) {
var node = this._router.define(name)[0]
node.cb = model
}
// Deprecated. Use Router.prototype.addRoute instead
Router.prototype.route = function BaseRouter_route (name, model) {
this._router.addRoute(name, model)
console.warn('Router.route is deprecated and will be removed in version 2.0. Please use Router.addRoute instead.')
this.addRoute(name, model)
}
Router.prototype.transitionTo = function BaseRouter_transitionTo (name, params) {
Router.prototype.transitionTo = function BaseRouter_transitionTo (name, params, cb) {
var self = this

@@ -35,2 +42,7 @@

if (typeof params === 'function') {
cb = params
params = null
}
var aborted = false

@@ -42,5 +54,10 @@ function abort () { aborted = true }

if (aborted) return
if (err) return self.emit('error', name, err)
if (err) {
if (typeof cb === 'function') cb(err)
else self.emit('error', name, err)
return
}
self.currentRoute = name
self.emit('transition', name, data)
if (typeof cb === 'function') cb(null, data)
else self.emit('transition', name, data)
}

@@ -55,3 +72,3 @@

// TODO: Detect queryParams
var data = model.fn(params || model.params, done)
var data = model.node.cb(params || model.param, done)
if (data) {

@@ -58,0 +75,0 @@ if (typeof data.then === 'function') {

{
"name": "base-router",
"version": "1.0.2",
"version": "1.1.0",
"description": "A simple and portable router for the client and server.",

@@ -41,4 +41,4 @@ "main": "index.js",

"inherits": "^2.0.1",
"routes": "^2.0.0"
"routington": "^1.0.3"
}
}

@@ -32,3 +32,3 @@ # base-router

#### Specifying Routes
This library uses the module [routes](https://github.com/aaronblohowiak/routes.js)
This library uses the module [routington](https://github.com/pillarjs/routington)
to specify and match routes. Please see their docs for route matching.

@@ -123,3 +123,3 @@

### `router.transitionTo(name[, params])`
### `router.transitionTo(name[, params, callback])`
Transitions to the given route `name`.

@@ -129,2 +129,5 @@

Optionally you can supply a `callback` which will be called instead of using the
`transition` and `error` events.
### `router.currentRoute`

@@ -131,0 +134,0 @@ The last resolved route we are currently on.

@@ -136,2 +136,16 @@ var test = require('tape')

test('callback with transitionTo', function (t) {
t.plan(1)
var router = new Router({
'/': function (params, done) {
done(null, params.test)
}
})
router.transitionTo('/', {test: 'testing'}, function (err, result) {
if (err) throw err
t.equal(result, 'testing')
t.end()
})
})
// TODO: Test current route
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc