Reputation: 410
I'm using my App.vent object to handle some back n forth between my Controller and my LayoutView. My LayoutView contains this:
events:{
'click @ui.addQuestion': 'addQuestion'
},
addQuestion: function(e){
var newModel = new App.ActivitySetupModule.Entities.Question();
App.vent.trigger('activity:questions:add:question', newModel)
}
This LayoutView gets swapped in and out of the 'mainRegion" region of my app like so in the Controller:
this.activityLayoutView.mainContentRegion.show(this.LayoutView);
And also in the Controller is Vent listening:
App.vent.on('activity:questions:add:question', function(model){
// ajax call
}
The problem is that everytime I swap out LayoutView to go to a new section, the ajax call gets called for everytime i swapped it out when I click on the addQuestion button. So if i came to this page 3 times where the Layout view was shown, then it will make the ajax call 3 times. But if i put a console.log in the addQuestion function, it will only ever display ONCE. So I don't get that. Is this a case of a zombie view? I have reasons for not binding and listening to the layout view object so I am hoping to use vent here.
Upvotes: 0
Views: 306
Reputation: 410
The reason was that my App.vent.listener was inside a callback in the controller initializer. The callback was called several times upon successful fetch of a collection so this was bound everytime the controller initialized. Since App doesn't get cleared away by itself and I wasn't doing it.. there was no cleanup.
Upvotes: 0