Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dist] Various small bug fixes. Lowercase on Arrays passed to .on; Co…
…rrectly pass `thisArg` to callback; Add `before`, `after`, and `on` from the root scope to runlists
  • Loading branch information
indexzero committed Dec 6, 2011
1 parent ed7d39e commit 9939e09
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/director/router.js
Expand Up @@ -203,7 +203,7 @@ Router.prototype.on = Router.prototype.route = function (method, path, route) {

if (Array.isArray(method)) {
return method.forEach(function (m) {
self.on(m, path, route);
self.on(m.toLowerCase(), path, route);
});
}

Expand Down Expand Up @@ -341,8 +341,9 @@ Router.prototype.invoke = function (fns, thisArg, callback) {
// Ignore the response here. Let the routed take care
// of themselves and eagerly return true.
//

if (callback) {
callback.apply(null, arguments);
callback.apply(thisArg, arguments);
}
});
}
Expand Down Expand Up @@ -413,12 +414,13 @@ Router.prototype.traverse = function (method, path, routes, regexp) {
//
current = exact = regexp + this.delimiter + r;


if (!this.strict) {
exact += '[' + this.delimiter + ']?';
}

match = path.match(new RegExp('^' + exact));

if (!match) {
//
// If there isn't a `match` then continue. Here, the
Expand All @@ -440,6 +442,12 @@ Router.prototype.traverse = function (method, path, routes, regexp) {
next.after = [routes[r].after].filter(Boolean);
next.matched = true;
next.captures = match.slice(1);

if (this.recurse && routes === this.routes) {
next.push([routes['before'], routes['on']].filter(Boolean));
next.after = next.after.concat([routes['after']].filter(Boolean))
}

return next;
}

Expand Down Expand Up @@ -467,6 +475,11 @@ Router.prototype.traverse = function (method, path, routes, regexp) {
if (this.recurse) {
fns.push([routes[r].before, routes[r].on].filter(Boolean));
next.after = next.after.concat([routes[r].after].filter(Boolean));

if (routes === this.routes) {
fns.push([routes['before'], routes['on']].filter(Boolean));
next.after = next.after.concat([routes['after']].filter(Boolean))
}
}

fns.matched = true;
Expand Down Expand Up @@ -509,7 +522,7 @@ Router.prototype.insert = function (method, path, route, parent) {

parent = parent || this.routes;
part = path.shift();
if (/\:|\*/.test(part)) {
if (/\:|\*/.test(part) && !/\\d|\\w/.test(part)) {
part = regifyString(part, this.params);
}

Expand Down

0 comments on commit 9939e09

Please sign in to comment.