jaredhanson/locomotive — pull request #116 by redking (2013-12-02 15:08:09+00:00)
Title: Update before filters to pass data as a second argument to next

This pull request resolves #114.

You may now optionally pass a second data argument to `next` in your before filters. For example

```javascript
var err;

controller.before('show', function(next) {
var data = {
band: 'Counting Crows'
};
next(err, data);
});

controller.before('show', function(next, data) {
data.album = 'August and Everything After';
next(err, data);
});

controller.show = function(data) {
this.band = data.band;
this.album = data.album;
this.render();
}
```

The data attribute is completely optional; existing code can continue to attach attributes to `this` if they wish, and do not need to change their filter function signatures.

After this change, the potential signatures for a before filter are

* `function(next)`
* `function(next, data)`
* `function(req, res, next)`
* `function(req, res, next, data)`

One thing to note - I originally modified the after filters so they would have the same behaviour. However, this introduced an issue with after callbacks designed to catch all errors. With the additional data argument, the signatures `function(req, res, next, data)` and `function(err, req, res, next)` had the same "arity". Thus either we would have to make `data` a required fifth argument in all error callback cases, or change the way in which after error callbacks are defined. I wasn't happy with either option; in any case, this functionality is only really of use in the before filters, in my opinion.

Anway, I've put the 'after' code aside for the moment; I can make a subsequent pull request if you decide you'd rather the filters to behave identically, or if you can think of a better way of handling this.