react-router
Advanced tools
Comparing version 0.12.1 to 0.12.2
@@ -64,2 +64,17 @@ "use strict"; | ||
function addRoutesToNamedRoutes(routes, namedRoutes) { | ||
var route; | ||
for (var i = 0, len = routes.length; i < len; ++i) { | ||
route = routes[i]; | ||
if (route.name) { | ||
invariant(namedRoutes[route.name] == null, "You may not have more than one route named \"%s\"", route.name); | ||
namedRoutes[route.name] = route; | ||
} | ||
if (route.childRoutes) addRoutesToNamedRoutes(route.childRoutes, namedRoutes); | ||
} | ||
} | ||
/** | ||
@@ -125,2 +140,3 @@ * Creates and returns a new router using the given options. A router | ||
this.cancelPendingTransition(); | ||
this.namedRoutes = {}; | ||
this.routes = []; | ||
@@ -135,2 +151,4 @@ }, | ||
addRoutesToNamedRoutes(routes, this.namedRoutes); | ||
this.routes.push.apply(this.routes, routes); | ||
@@ -166,3 +184,3 @@ }, | ||
} else { | ||
var route = to instanceof Route ? to : Route.findRouteByName(this.routes, to); | ||
var route = to instanceof Route ? to : this.namedRoutes[to]; | ||
@@ -169,0 +187,0 @@ invariant(route instanceof Route, "Cannot find a route named \"%s\"", to); |
@@ -20,84 +20,21 @@ "use strict"; | ||
Route.prototype.toString = function () { | ||
var string = "<Route"; | ||
if (this.name) string += " name=\"" + this.name + "\""; | ||
string += " path=\"" + this.path + "\">"; | ||
return string; | ||
}; | ||
/** | ||
* Appends the given route to this route's child routes. | ||
*/ | ||
Route.prototype.appendChildRoute = function (route) { | ||
invariant(route instanceof Route, "route.appendChildRoute must use a valid Route"); | ||
Route.prototype.appendChild = function (route) { | ||
invariant(route instanceof Route, "route.appendChild must use a valid Route"); | ||
if (!this.childRoutes) this.childRoutes = []; | ||
if (route.name) { | ||
invariant(this.childRoutes.every(function (childRoute) { | ||
return childRoute.name !== route.name; | ||
}), "Route %s may not have more than one child route named \"%s\"", this, route.name); | ||
} | ||
this.childRoutes.push(route); | ||
}; | ||
/** | ||
* Allows looking up a child route using a "." delimited string, e.g.: | ||
* | ||
* route.appendChildRoute( | ||
* Router.createRoute({ name: 'user' }, function () { | ||
* Router.createRoute({ name: 'new' }); | ||
* }) | ||
* ); | ||
* | ||
* var NewUserRoute = route.lookupChildRoute('user.new'); | ||
* | ||
* See also Route.findRouteByName. | ||
*/ | ||
Route.prototype.lookupChildRoute = function (names) { | ||
if (!this.childRoutes) return null; | ||
Route.prototype.toString = function () { | ||
var string = "<Route"; | ||
return Route.findRouteByName(this.childRoutes, names); | ||
}; | ||
if (this.name) string += " name=\"" + this.name + "\""; | ||
/** | ||
* Searches the given array of routes and returns the route that matches | ||
* the given name. The name should be a . delimited string like "user.new" | ||
* that specifies the names of nested routes. Routes in the hierarchy that | ||
* do not have a name do not need to be specified in the search string. | ||
* | ||
* var routes = [ | ||
* Router.createRoute({ name: 'user' }, function () { | ||
* Router.createRoute({ name: 'new' }); | ||
* }) | ||
* ]; | ||
* | ||
* var NewUserRoute = Route.findRouteByName(routes, 'user.new'); | ||
*/ | ||
Route.findRouteByName = function (routes, names) { | ||
if (typeof names === "string") names = names.split("."); | ||
string += " path=\"" + this.path + "\">"; | ||
var route, foundRoute; | ||
for (var i = 0, len = routes.length; i < len; ++i) { | ||
route = routes[i]; | ||
if (route.name === names[0]) { | ||
if (names.length === 1) return route; | ||
if (!route.childRoutes) return null; | ||
return Route.findRouteByName(route.childRoutes, names.slice(1)); | ||
} else if (route.name == null) { | ||
// Transparently skip over unnamed routes in the tree. | ||
foundRoute = route.lookupChildRoute(names); | ||
if (foundRoute != null) return foundRoute; | ||
} | ||
} | ||
return null; | ||
return string; | ||
}; | ||
@@ -189,3 +126,3 @@ | ||
parentRoute.appendChildRoute(route); | ||
parentRoute.appendChild(route); | ||
} | ||
@@ -192,0 +129,0 @@ |
{ | ||
"name": "react-router", | ||
"version": "0.12.1", | ||
"version": "0.12.2", | ||
"description": "A complete routing library for React.js", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
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
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
0
74985
1968