javascriptdom-eventstitaniumaddeventlistenerappcelerator-mobile

Javascript events multiplying


I can't see the forest through the trees. I have a contacts tab with a tableView containing rows that can be deleted. If (in the same session) I delete 'n' number of rows, the subsequent events are called 'n' times.

Here is my code. (I tried to pare this down to isolate the problem.)

The specific event that is being duplicated (...triplicated, etc) is ui.contactDestroyed because I am getting multiple AlertDialogs as well as multiple resulting app.updateContacts and ui.contactsUpdated fires in my log.

Thanks for any critiques of my code (related to the issue or not).

Note: According to my server log, the otg.remote.destroyContact XHR is appropriately being sent once for each legitimate request. The otg.remote.getContacts XHR is sent multiple times because it is tied to the culprit, ui.contactDestroyed.


Solution

  • line 197 and line 188 should not be in the eventListener, the way the code is written right now, everytime someone deletes something, you are adding a new eventListener, that is why it is happening multiple times.

    Add application wide eventListeners once