Skip to content

Commit

Permalink
Revert "Minor enhancements, including changes to this.extend."
Browse files Browse the repository at this point in the history
This reverts commit 09602f3.
  • Loading branch information
indexzero committed Dec 17, 2012
1 parent d4788e9 commit 82efe73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
12 changes: 6 additions & 6 deletions lib/director/http/index.js
Expand Up @@ -22,15 +22,15 @@ var Router = exports.Router = function (routes) {
//
// ### Extend the `Router` prototype with all of the RFC methods.
//
this.params = {};
this.routes = {};
this.methods = ['on', 'after', 'before'];
this.scope = [];
this._methods = {};
this.recurse = 'forward';
this._attach = [];

//
// ### Inherit properties from the `director.Router` constructor.
//
director.Router.apply(this);

this.extend(exports.methods);
this.extend(exports.methods.concat(['before', 'after']));
this.configure();
this.mount(routes || {});
};
Expand Down
41 changes: 11 additions & 30 deletions lib/director/router.js
Expand Up @@ -180,7 +180,9 @@ var Router = exports.Router = function (routes) {
Router.prototype.configure = function (options) {
options = options || {};

this.extend(this.methods);
for (var i = 0; i < this.methods.length; i++) {
this._methods[this.methods[i]] = true;
}

this.recurse = options.recurse || this.recurse || false;
this.async = options.async || false;
Expand Down Expand Up @@ -716,45 +718,24 @@ Router.prototype.insert = function (method, path, route, parent) {
// for each of the specified `methods`
//
Router.prototype.extend = function(methods) {
var self = this;
var self = this,
len = methods.length,
i;

function extend(method) {
self._methods[method] = true;

//
// ### Function to be used in our methods.
//
function route() {
self[method] = function () {
var extra = arguments.length === 1
? [method, '']
: [method];

self.on.apply(self, extra.concat(Array.prototype.slice.call(arguments)));
}

//
// ### Set the method if it's not listed as a default in `this.methods`.
//
if (!~self.methods.indexOf(method)) {
//
// ### Method has already been defined.
//
if (self._methods[method]) {
//
// ### Method is our route function. No action required.
//
if (self[method] === route) return;
}
//
// ### If all is good, set the method to our route function.
//
self[method] = route;
}
};
}

methods.forEach(function(method) {
extend(method);
});
for (i = 0; i < len; i++) {
extend(methods[i]);
}
};

//
Expand Down

0 comments on commit 82efe73

Please sign in to comment.