Question

I'm reading the EventAggregator doc in Backbone.Wreqr. It can be used like the following.

MyApp.vent.trigger("some:namespaced:event");

MyApp.vent.on("some:namespaced:event", function(){
  // ...
});

I cannot understand if, once set up an handler within a view, I need to remove it or Marionette will do it for me in onClose method or somewhere else? If I need to remove it, what is the best approach I can follow? Is it necessary just to off that event? Does the same apply for Commands using removeHandler?

Could you point me in the right direction?

Was it helpful?

Solution

It depends of your situation. If you don't want to listen some event, when module doesn't work, you can subscribe to module "stop" event and execute off for all necessary events.

module.on("stop", function(){
  App.vent.off(someMethods);
});

As usuall, view doesn't use global event aggregation. But if you use, you shuold use

this.listenTo( App.vent, "someEvent", function(){...} )

and then Marionette remove this handler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top