route-node
Advanced tools
Comparing version
@@ -73,5 +73,9 @@ 'use strict'; | ||
this.children.push(route); | ||
// Push greedy splats to the bottom of the pile | ||
this.children.sort(function (childA, childB) { | ||
return childA.hasSplatParam ? -1 : 1; | ||
// Push greedy spats to the bottom of the pile | ||
this.children.sort(function (a, b) { | ||
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1; | ||
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1; | ||
if (!a.parser.hasUrlParams && b.parser.hasUrlParams) return -1; | ||
if (!b.parser.hasUrlParams && a.parser.hasUrlParams) return 1; | ||
return 0; | ||
}); | ||
@@ -78,0 +82,0 @@ } else { |
@@ -80,5 +80,9 @@ (function (global, factory) { | ||
this.children.push(route); | ||
// Push greedy splats to the bottom of the pile | ||
this.children.sort(function (childA, childB) { | ||
return childA.hasSplatParam ? -1 : 1; | ||
// Push greedy spats to the bottom of the pile | ||
this.children.sort(function (a, b) { | ||
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1; | ||
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1; | ||
if (!a.parser.hasUrlParams && b.parser.hasUrlParams) return -1; | ||
if (!b.parser.hasUrlParams && a.parser.hasUrlParams) return 1; | ||
return 0; | ||
}); | ||
@@ -85,0 +89,0 @@ } else { |
@@ -43,4 +43,10 @@ import Path from 'path-parser/modules/Path' | ||
this.children.push(route) | ||
// Push greedy splats to the bottom of the pile | ||
this.children.sort((childA, childB) => childA.hasSplatParam ? -1 : 1) | ||
// Push greedy spats to the bottom of the pile | ||
this.children.sort((a, b) => { | ||
if (!a.parser.hasSpatParam && b.parser.hasSpatParam) return -1 | ||
if (!b.parser.hasSpatParam && a.parser.hasSpatParam) return 1 | ||
if (!a.parser.hasUrlParams && b.parser.hasUrlParams) return -1 | ||
if (!b.parser.hasUrlParams && a.parser.hasUrlParams) return 1 | ||
return 0; | ||
}) | ||
} else { | ||
@@ -47,0 +53,0 @@ // Locate parent node |
{ | ||
"name": "route-node", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A package to create a tree of named routes#", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/route-node.js", |
@@ -70,2 +70,12 @@ 'use strict'; | ||
it('should throw an error when trying to add a route which parent doesn\'t exist', function () { | ||
var root = new RouteNode('', '', [ | ||
{name: 'home', path: '/home'} | ||
]); | ||
(function () { | ||
root.add({name: 'nested.route', path: '/route'}) | ||
}).should.throw(); | ||
}); | ||
it('should instanciate a RouteNode object from RouteNode objects', function () { | ||
@@ -162,4 +172,4 @@ var node = new RouteNode('', '', [ | ||
new RouteNode('splat', '/*id'), | ||
new RouteNode('list', '/list'), | ||
new RouteNode('view', '/view/:id') | ||
new RouteNode('view', '/view/:id'), | ||
new RouteNode('list', '/list') | ||
]); | ||
@@ -166,0 +176,0 @@ |
35398
3.63%702
3.24%