Skip to content

Commit

Permalink
Make ext events private
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Mar 12, 2013
1 parent cc13017 commit d38c2e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions lib/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ var internals = {};

module.exports = internals.Ext = function () {

this.onRequest = null; // New request, before handing over to the router (allows changes to the request method, url, etc.)
this.onPreHandler = null; // After validation and body parsing, before route handler
this.onPostHandler = null; // After route handler returns, before sending response
this._events = {
onRequest: null, // New request, before handing over to the router (allows changes to the request method, url, etc.)
onPreHandler: null, // After validation and body parsing, before route handler
onPostHandler: null // After route handler returns, before sending response
};
};


Expand All @@ -34,10 +36,10 @@ internals.Ext.prototype._add = function (event, func, options, plugin) {

Utils.assert(['onRequest', 'onPreHandler', 'onPostHandler'].indexOf(event) !== -1, 'Unknown event type: ' + event);

this[event] = this[event] || []
this._events[event] = this._events[event] || []

var ext = {
priority: this[event].length,
priority: this._events[event].length,
before: Utils.clone(options.before) || [],
after: Utils.clone(options.after) || [],
group: plugin || '?',
Expand All @@ -53,14 +55,14 @@ internals.Ext.prototype._add = function (event, func, options, plugin) {

// Insert event

this[event].push(ext);
this._events[event].push(ext);
this.sort(event);
};


internals.Ext.prototype.sort = function (event) {

var input = this[event];
var input = this._events[event];
if (!input) {
return;
}
Expand All @@ -71,13 +73,13 @@ internals.Ext.prototype.sort = function (event) {

// Apply

this[event] = sorted;
this._events[event] = sorted;
};


internals.Ext.prototype.invoke = function (request, event, callback) {

var handlers = this[event]; // onRequest, onPreHandler, onPostHandler
var handlers = this._events[event]; // onRequest, onPreHandler, onPostHandler
if (!handlers) {
return callback();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Ext', function () {

var ext = new Ext();
ext.sort('onRequest');
expect(ext.onRequest).to.equal(null);
expect(ext._events.onRequest).to.equal(null);
done();
});
});
Expand Down

0 comments on commit d38c2e2

Please sign in to comment.