0
votes

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.

1
addQuestion is only called once, though?! That's odd. If it was a zombie view, the function would get called multiple times. Is there anything else in the app triggering this event?Cory Danielson
@CoryDanielson Yea,that's what's driving me nuts. Nope, this is the only spot where it's being triggered.neptunian
Hrm, so I guess that means that the code which binds this event (App.vent.on('activity:...) must be getting called multiple times as well, and the event is not being unbound. That would result in the problem that you're having.... How/when is that last code snippit from the Controller called?Cory Danielson

1 Answers

0
votes

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.