I am curious to know just what logic lies in which layer with respect to the new ember routing and controllers:
If we take the route below as an example:
step1: Ember.Route.extend
route: '/step1'
connectOutlets: (router, event) ->
exercise = WZ.Exercise.createRecord()
router.get('exercisesNewStep1Controller').set 'groups', WZ.store.find(WZ.Group)
router.get('exercisesNewController').connectOutlet 'step', 'exercisesNewStep1', exercise
My ExercisesNewStep1Controller is currently logicless:
WZ.ExercisesNewStep1Controller = Em.Controller.extend()
The recommended advice seems to be to have the route just take care of assigning the correct outlet to the correct controller with any other logic in the controller.
Should I refactor my controller to something like this:
WZ.ExercisesNewStep1Controller = Em.Controller.extend
createGroup: ->
@set 'groups', WZ.store.find(WZ.Group)
This is a very simple example but I think the logic holds.
I am a bit confused what lies where with all the layers. I think there is a small amount of overhead by having to create all these xxxController, xxxView files and coupling between them.
I love ember but I just want to raise this point.
I had a few exchanges with Tilde team, and Tom Dale teached us to follow the way proposed by hvgotcodes.
But a refinement occured after a discussion with Peter Wagenet: As a reply to my interrogation, Peter & Yehuda mitigated the position we held from Tom explanations.
So I would summarize the whole picture saying:
The reason is any processing should be scoped inside a given route, which ensure a coherent behavior of the whole app, not opening all the possible processings to any part of the app.
In Sproutcore (someone will speak up if this doesn't apply in Ember, which derives from Sproutcore), controllers should almost always just be dumb proxies. They don't do anything.
Assuming that holds true for Ember, I wouldn't move the logic there.
The recommended advice seems to be to have the route just take care of assigning the correct outlet to the correct controller with any other logic in the controller.
I think that is correct. From the examples I see online, Routes are just states. Going to github, this link, you will see that Routes extend States. So application level events should be handled in your Routes (i.e. States). It's here where you would get relevant objects and put them in applicable controllers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With