millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

Callback on matching parameters #123

Closed FREEZX closed 9 years ago

FREEZX commented 9 years ago

Express's router allows for specifying callbacks when parameters are matched. (http://expressjs.com/api.html) That is a very useful feature because it allows you to define, for example, a function to retreive an object from the database upon route access, thus keeping code DRY.

This approach is used by Mean.js: https://github.com/meanjs/mean/blob/master/app/routes/articles.server.routes.js#L21 https://github.com/meanjs/mean/blob/master/app/controllers/articles.server.controller.js#L90

Note how it keeps all the other functions clean, removing the necessity for initial database queries within the other route callbacks that need the article.

This same feature can be very useful if also added to crossroads.js.

millermedeiros commented 9 years ago

this would increase complexity drastically since right now every single method on crossroads is synchronous.. I would only implement something like this for v2.0 release - if we decide to add async support (see #82)