base-router
Advanced tools
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17802
366
152
+ Addedroutington@^1.0.3
+ Addeddeep-equal@1.0.1(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addedflatten@0.0.1(transitive)
+ Addedhttp-assert@1.5.0(transitive)
+ Addedhttp-errors@1.8.1(transitive)
+ Addedroutington@1.0.3(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedtoidentifier@1.0.1(transitive)
- Removedroutes@^2.0.0
- Removedroutes@2.1.0(transitive)