Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add multiple matches. This feature is currently dangerous.

  • Loading branch information...
commit bdc12ce6f27735013d13ad5614b2da1e31650cc3 1 parent 2a50485
@DrPheltRight authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/waypoint/router.coffee
View
14 lib/waypoint/router.coffee
@@ -6,13 +6,14 @@ isArray or= ((obj) -> Object.prototype.toString.call(obj) is '[object Array]')
class Router
constructor: (config) ->
if config
- for key in ['routes', 'baseUri', 'notFound']
+ for key in ['routes', 'baseUri', 'notFound', 'multi']
@[key] = config[key] if config[key]?
routeMap = config.routeMap if config.routeMap?
@routes or= []
@baseUri or= ''
+ @multi or= no
@routeMap(routeMap) if routeMap?
route: (method, uri, callback) ->
@@ -51,18 +52,23 @@ class Router
return @
dispatch: (method, uri, scope = {}) ->
+ hasMatched = no
+
for route in @routes
continue unless matches = route.match(method, uri)
+ hasMatched = yes
+
if isArray(route.callback)
callbacks = route.callback
else
callbacks = [route.callback]
c.apply(scope, matches) for c in callbacks
- return true
+
+ break unless @multi
- @notFound.call(scope) if @notFound?
- return false
+ @notFound.call(scope) if @notFound? and hasMatched is no
+ return hasMatched
module.exports = Router
Please sign in to comment.
Something went wrong with that request. Please try again.