forked from expressjs/express
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored router. Closes expressjs#639
- Loading branch information
Showing
7 changed files
with
460 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
/*! | ||
* Express - router - Collection | ||
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* Expose `Collection`. | ||
*/ | ||
|
||
module.exports = Collection; | ||
|
||
/** | ||
* Initialize a new route `Collection` | ||
* with the given `router`. | ||
* | ||
* @param {Router} router | ||
* @api private | ||
*/ | ||
|
||
function Collection(router) { | ||
Array.apply(this, arguments); | ||
this.router = router; | ||
} | ||
|
||
/** | ||
* Inherit from `Array.prototype`. | ||
*/ | ||
|
||
Collection.prototype.__proto__ = Array.prototype; | ||
|
||
/** | ||
* Remove the routes in this collection. | ||
* | ||
* @return {Collection} of routes removed | ||
* @api public | ||
*/ | ||
|
||
Collection.prototype.remove = function(){ | ||
var router = this.router | ||
, len = this.length | ||
, ret = new Collection(this.router); | ||
|
||
for (var i = 0; i < len; ++i) { | ||
if (router.remove(this[i])) { | ||
ret.push(this[i]); | ||
} | ||
} | ||
|
||
return ret; | ||
}; | ||
|
Oops, something went wrong.