Router API, in addition to `this`, inject an object or functions?


#1

Just a quick thought.

App.Router.map(function() {
  this.resource('posts');
  this.route('about');
});

App.Router.map(function(resource, route) {
  resource('posts');
  route('about');
});

Only benefit is minification and less typing, not sure if its worth it.


#2

Good point. But my guess is that in most apps the size of the router is pretty small compared to the rest of the js. So the decreased filesize due to minification must be insignificant.

You could do this if you want to type less:

App.Router.map(function() {
  var resource = this.resource,
      route = this.route;
  resource('posts');
  route('about');
});

Or if you really want to type less:

App.Router.map(function() {
  var a = this.resource,
      b = this.route;
  a('posts');
  b('about');
});

#3

Would injecting an object make it a little more obvious to new users how to find help? If examples showed something like:

App.Router.map(function(dsl){
  dsl.resource("..");
  dsl.route("..");
});

that parameter gives the user a clue where to look for documentation of that object (for example, I didn’t know there are a couple extra methods on Ember.RouterDSL until I looked it up to provide this example). Of course, I wouldn’t recommend “dsl” as the parameter name, but figuring out something better that would provide a hint where to look.