Refactor RouteNode → flatten for better readability

master
Buddy Sandidge 9 years ago
parent 7c34964dff
commit f89bc55105

@ -48,27 +48,30 @@ assign(RouteNode.prototype, {
get: function get(parts, args, done) {
parts = parts || []
args = args || []
if (parts.length === 0) {
return done(null, this.handler, this.context, args)
}
var part = parts.shift()
var childNode = this._children[part]
if (childNode) {
return childNode.get(parts, args, done)
} else {
// Check exact matches
if (this._children[part]) {
return this._children[part].get(parts, args, done)
}
// Check regex matches
var results = this._getRegexChild(part)
if (results && results.node) {
return results.node.get(parts, args.concat(results.args), done)
} else {
}
// Check function matches
results = this._getFunctionChild(part)
if (results && results.node) {
return results.node.get(parts, args.concat(results.args), done)
} else {
return done(new Error('not found'))
}
}
}
return done(new Error('not found'))
},
_getRegexChild: function _getRegexChild(part) {

Loading…
Cancel
Save