I have read most of the beginner guides on the Ember.js site but I am still confused about the correct place to put stuff.
Route - from online research people suggested putting routing related logic in the route. That is all good, but the only thing I can think of is
this.transisionTo()
. I read somewhere else that all model related operations should be in the route because that is where themodel
field is defined. Is this correct? What are some good use cases of puttingactions
in the route over the controller?View - Currently, I can't see the point of the view. The docs say that it handles native DOM events but I will probably always use the
{{action}}
helper which will be handled by the controller. So what are some good use cases of using the view over the controller in regards to actions? What are some good use cases of the view generally considering I will be using components over views for reusable code.Controller - It appears to me that the controller can do anything the View or Route can do. It can transition using
this.transitionToRoute()
, it can save models usingthis.get('model').save()
and can handle actions using the{{action}}
helper. All the beginner tutorials seem to ignore the view altogether and use the controller instead. What are some good use cases of using the Controller over the View or Route?
I guess this all comes down to poor understanding of how everything hangs together. I can't find anything online or in the docs that is explicit about the grey areas such as where to use the {{action}}
helper for different scenarios. Links to some good materials would be helpful too.
actions
can be pointed at a view... What if you want to turn a div green three seconds after it renders? Controller can't help you there. :) The view, however, has a handy-dandy hook for such a scenario. Go look at all the available view hooks and methods and the utility of views will be obvious. – Matthew BlancarteEmber.run.later(function(){ self.set('isGreen', true);}, 3000);
where isGreen is bound to the div class.<div {{bind-attr class="isGreen:green"}}
– jax{{bind-attr}}
is meant to bind model and computed properties, not create a visual effect 3 seconds after rendering. You would want to put thatEmber.run.later
into thedidInsertElement
of the view. – Matthew Blancarte