Removed `Collection`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 9abba7d · Browse files · 2 files·+0 added−158 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+0 added−158 removed
- other:+0 added−158 removed
Provenance
- Commit
9e251d1- Tree
6446d5d- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
9abba7d
2 files changed+0 added−158 removed
deleted:lib/router/collection.js-52 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
/*! * 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) { Object.defineProperty(this, 'router', { value: 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;};
modified:lib/router/index.js-106 removed
7 unmodified lines8 * Module dependencies.9 */10 11 var Route = require('./route')12- , Collection = require('./collection')12 , utils = require('../utils')13 , debug = require('debug')('express:router')14 , parse = require('url').parse;15 18 unmodified lines34 35 function Router(options) {36 options = options || {};37 var self = this;39- this.routes = new Collection;38 this.map = {};39 this.params = {};40 this._params = [];41 this.caseSensitive = options.caseSensitive;41 unmodified lines83 return this;84 };85 86 /**89- * Return a `Collection` of all routes defined.90- *91- * @return {Collection}92- * @api public93- */94-95-Router.prototype.all = function(){96- return this.find(function(){97- return true;98- });99-};100-101-/**102- * Remove the given `route`, returns103- * a bool indicating if the route was present104- * or not.105- *106- * @param {Route} route107- * @return {Boolean}108- * @api public109- */110-111-Router.prototype.remove = function(route){112- var routes = this.map[route.method]113- , len = routes.length;114-115- // remove from array116- var i = this.routes.indexOf(route);117- this.routes.splice(i, 1);118-119- // remove from map120- for (var i = 0; i < len; ++i) {121- if (route == routes[i]) {122- routes.splice(i, 1);123- return true;124- }125- }126-};127-128-/**129- * Return routes with route paths matching `path`.130- *131- * @param {String} method132- * @param {String} path133- * @return {Collection}134- * @api public135- */136-137-Router.prototype.lookup = function(method, path){138- return this.find(function(route){139- return path == route.path140- && (route.method == method141- || method == 'all');142- });143-};144-145-// /**146-// * Return routes with regexps that match the given `url`.147-// *148-// * @param {String} method149-// * @param {String} url150-// * @return {Collection}151-// * @api public152-// */153-// 154-// Router.prototype.match = function(method, url){155-// return this.find(function(route){156-// return route.match(url)157-// && (route.method == method158-// || method == 'all');159-// });160-// };161-162-/**163- * Find routes based on the return value of `fn`164- * which is invoked once per route.165- *166- * @param {Function} fn167- * @return {Collection}168- * @api public169- */170-171-Router.prototype.find = function(fn){172- var len = methods.length173- , ret = new Collection(this)174- , method175- , routes176- , route;177-178- for (var i = 0; i < len; ++i) {179- method = methods[i];180- routes = this.map[method];181- if (!routes) continue;182- for (var j = 0, jlen = routes.length; j < jlen; ++j) {183- route = routes[j];184- if (fn(route)) ret.push(route);185- }186- }187-188- return ret;189-};190-191-/**87 * Route dispatcher aka the route "middleware".88 *89 * @param {IncomingMessage} req90 * @param {ServerResponse} res218 unmodified lines309 });310 311 // add it312 (this.map[method] = this.map[method] || []).push(route);418- this.routes.push(route);313 return this;314 };