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) { get: function get(parts, args, done) {
parts = parts || [] parts = parts || []
args = args || [] args = args || []
if (parts.length === 0) { if (parts.length === 0) {
return done(null, this.handler, this.context, args) return done(null, this.handler, this.context, args)
} }
var part = parts.shift() var part = parts.shift()
var childNode = this._children[part]
if (childNode) { // Check exact matches
return childNode.get(parts, args, done) if (this._children[part]) {
} else { return this._children[part].get(parts, args, done)
var results = this._getRegexChild(part)
if (results && results.node) {
return results.node.get(parts, args.concat(results.args), done)
} else {
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'))
}
}
} }
// Check regex matches
var results = this._getRegexChild(part)
if (results && results.node) {
return results.node.get(parts, args.concat(results.args), done)
}
// Check function matches
results = this._getFunctionChild(part)
if (results && results.node) {
return results.node.get(parts, args.concat(results.args), done)
}
return done(new Error('not found'))
}, },
_getRegexChild: function _getRegexChild(part) { _getRegexChild: function _getRegexChild(part) {

Loading…
Cancel
Save