Autoload callback with request (backward compatible) #23

Merged
merged 2 commits into from Jun 29, 2011

Conversation

Projects
None yet
2 participants

Autoload will call with the request if the callback can accept additional args
Issue #22

index.js
@@ -58,14 +58,21 @@ Resource.prototype.load = function(fn){
this.loadFunction = fn;
this.app.param(this.id, function(req, res, next){
- fn(req.params[id], function(err, obj){
+ var callback = function(err, obj){
@tj

tj Jun 27, 2011

Owner

function callback(

@pacovell

pacovell Jun 27, 2011

NP -- for my benefit, can you explain if this is stylistic or functional?

@tj

tj Jun 29, 2011

Owner

just stylistic, though it gives the function a name so that it will display in stack traces, but also a locally defined function so it's functionally equivalent but preferred

index.js
+ };
+
+ // Maintain backward compatibility
+ if (fn.length === 2) {
@tj

tj Jun 27, 2011

Owner

2 == fn.length

Owner

tj commented Jun 27, 2011

other than that, looks good

tj added a commit that referenced this pull request Jun 29, 2011

Merge pull request #23 from donedotcom/master
Added request to autoload callback [donedotcom]

@tj tj merged commit 456df1b into expressjs:master Jun 29, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment