Dom Event Best Practices

Hey All,

New Ember developer here and have some best practice questions. I was reading through the guides and did not really find my answer. It seems that you can handle DOM interactions in both the view and the controller via actions. I’m just curious what the best practice is for this? Do you reserve complex DOM intercations for views and simple interactions for controller actions?

Example: I’ve got a list of items that have a a click action on them. When the item is clicked we simply add a class to change the display. My Ember CLI app already has the controller/template all tied together, does it make sense to generate a view for this route to add simple click interactions or is it okay to handle those in the controller actions?

I’m so new to Ember and don’t have anyone in my office that’s developed Ember before so im struggling with some of this best practice sort of stuff.

I believe your “items” should be components, not views. And those can handle “click” action internally by encapsulating “active” or whatever name you gave to that flag as a part of the component’s state. Component should be then rendered using its state.