3
votes

I'm been playing with ember.js off and on the last few months and always end up asking "what role does the controller play" because it usually looks something like this when I'm done

App.Controller = Ember.Controller.extend({
  content: null
});

If I have any basic validation requirements I tend to do these in the view itself.

If I need to populate a controllers content I do this in the router (though I'd prefer to reduce the # of responsibilities this object seems to have in the current version of ember).

My models are persisted using a separate adapter via ember-data with some domain logic like behavior when needed.

What I'm left with in every app I've built is a thin (very very logic less) controller as shown above. I do find this is a good place to do sorting / pagination / search / filter / etc on the items but what else should this controller object be responsible for in a well design ember.js app?

1

1 Answers

3
votes

As you say, sorting / pagination / search / filter (BTW most of those is supported by Ember.ArrayController)

I think other stuff could be computed properties around the content (model), and then the view relies on those computed properties instead of doing the job by itself.

Perhaps it could be a good place to track and persist a view state (for example collapse/expand), which cannot be persisted in the view itself because it's destroyed/created at each time.