Ember.Route.transitionTo VS Ember.Controller.transitionToRoute (naming concern)


#1

Why does the same functionality have different naming depending on what component you are?

I have this code in my Controller:

this.transitionToRoute('posts');

If I want to implement same behaviour in a Route I have to write this instead:

this.transitionTo('posts');

IMHO: Looks like… uhmm… not elegant :confused:


#2

Can you clarify what you mean? Maybe giving an example of what you have in mind might help.


#3

Its common sense.

Ember.Route.transitionTo – Transtioning from one route to another (Its a route so no need for the suffix “Route”)

Ember.Controller.transitionToRoute – You in a controller and you are changing Routes hence the suffix “Route”

HTH


#4

@mtangoo In my opinion, I don’t see it should be necessary to think where I am when I am thinking in where I want to go, specially when both method implementations require the same input and the final result is the same.


#5

@vikram7 example added to the question


#6

I think you’re right — it’s a little weird. That being said, there is an RFC for a new Router Service that would replace both of those with a service that has it’s own hooks in whatever Ember Object you inject it into. So you’d do:

this.get('router').transitionTo('planet.mars');

It’s got a bunch of other nice little ideas too. Not sure whether it’s being actively developed or when we should expect something.


#7

@Spencer_Price that has more sense, not only because the naming thing is more coherent but because there is a Module who is charge of the transition this.get('router') and not the Component where your code is: this .

It is taking me a lot of effort to understand the Ember philosophy, a very few things are intuitive for me… yet :slight_smile:


#8

You’re right that naming isn’t that intuitive but then we have to live with that until something changes


#9

for future reference you will need to inject it into your controller with

router: service('-routing'),