I'm working with an App in TiShadow that has some Global event listeners. [Ti.App.addEventListeners]. I've created a 'wrapping' function to try to remove all the listeners on App startup if using TiShadow, but I'm not having much luck. They keep getting 're-regsitered' every time the App reruns and never removed. Hence, they are firing multiple times. Is there a best practice for this?
listeners.js:
var globalListeners = [];
exports.registerGlobalListener = function(evt, _function) {
globalListeners.push({
evt : evt,
func : _function
});
Ti.App.addEventListener(evt, _function);
};
exports.clearAllListeners = function() {
Ti.API.info('clearing all global listeners'); // <- This never runs... _.each(globalListeners, function(listener) {
Ti.App.removeEventListener(listener.evt, listener.func);
});
globalListeners = [];
};
//Code
listeners.registerGlobalListener('resume', function() {
// Do Something
});
app.js
// Shim for TiShadow
try {
exports.close = function() {
listeners.clearAllListeners();
tabGroup.close();
};
} catch (e) {
}