Overriding activate vs listening 'activate' event?


#1

Right now Ember Route class provides activate/deactivate events as well as the methods. I want to collect some analytics on entering the routes.

The guide suggest listening to the event.

App.ApplicationRoute = Ember.Route.extend({
  collectAnalytics: function(){
    collectAnalytics();
  }.on('activate')
});

I would like to know what is the preferred way used by everyone, listening the event or overriding the method?


#2

I prefer to listen to the event instead of overriding it as i tend to forget to call super. Not calling super bite me awhile back using one of the ember-simple-auth route mixins which lead to some nasty bugs.

I think the the non-prototype extension using method of listening on the event is preferred though:

const on = Em.on;
App.ApplicationRoute = Ember.Route.extend({
  collectAnalytics: on('activate', function() {
    collectAnalytics();
  })
});