Im having a strange problem where the onDestroy() method of my ItemView never seems to run. I'm using Marionette v 2.2.1. Here's a very simplified version of what I've got.
myItemView.js
-------------
initialize: function() {
console.log('ItemView init');
var self = this;
this.listenTo(eventsModel, 'change', function(){
console.log('changed, lets do something');
self.doSomething();
});
this.listenTo(eventsModel, 'destroy', function(){
console.log('lets destroy ourselves');
self.destroy();
});
}
onDestroy: function() {
console.log('hurray, destroyed!');
this.stopListening();
}
doSomething: function() {
console.log('doing something');
}
myController.js
---------------
var myView = new myItemView({model: aModel})
eventsModel.trigger('change');
eventsModel.trigger('destroy');
output:
//ItemView init
//changed, lets do something
//doing something
//lets destroy ourselves
As you can see onDestroy() never fires... what am I missing?
onBeforeDestroy
callback? Btw, events handled withthis.listenTo
are unbound automatically when the view is destroyed, see github.com/marionettejs/backbone.marionette/blob/master/docs/…. – seebiscuit