Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top