Yes, you must add the close method to your views. EventBinder does not deny what this Zombies post says. Rather, it helps automate many processes, making it easier to disable all of your events in the view.
Take a look at the source code of Marionette.View for an example of how it is used:
https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L9 https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view .js # L16 https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L97
If you are using Marionette, you do not need to add the close method yourself or add a mediation event yourself. That was for you.
If you want to add this to your own views, it's easy:
MyView = Backbone.View.extend({ initialize: function(){ // add the event binder this.eventBinder = new Backbone.EventBinder(); // bind some stuff this.eventBinder.bindTo(this.model, "change:foo", this.doStuff, this); }, close: function(){ // ... other stuff this.eventBinder.unbindAll(); } });
source share