{ "id": "119909", "key": "AC-3252", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "11", "description": "Is not a bug in our product", "name": "Not Our Bug" }, "resolutiondate": "2013-09-18T08:06:02.000+0000", "created": "2013-09-13T12:19:27.000+0000", "labels": [ "addeventlistener", "eventlistener", "removeeventlistener" ], "versions": [], "issuelinks": [], "assignee": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "updated": "2016-03-08T07:57:39.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "As the following test shows:\r\n\r\n* Calling {{addEventListener}} on exact the same object, for the same event and using the same callback will cause the callback to get fired for as many times it has been added.\r\n* Calling {{removeEventListener}} on that same object, event and with the same callback will only remove one of the previous times it was added.\r\n\r\nI'd expect the same callback to be only added one, which should be doable by just checking if the object the callback param refers to is already a listener for that event.\r\n\r\n{code}\r\nvar count = 0;\r\nvar fired = 0;\r\n\r\nfunction listener() {\r\n fired++;\r\n firedLabel.text = 'Fired: ' + fired;\r\n}\r\n\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor:'#fff'\r\n});\r\n\r\nvar remove = Ti.UI.createButton({\r\n top: 100,\r\n left: 25,\r\n title: 'Remove'\r\n});\r\n\r\nvar countLabel = Ti.UI.createLabel({\r\n top: 100,\r\n text: 'Added: ' + count\r\n});\r\n\r\nvar add = Ti.UI.createButton({\r\n top: 100,\r\n right: 25,\r\n title: 'Add'\r\n});\r\n\r\nvar fire = Titanium.UI.createButton({\r\n top: 300,\r\n left: 25,\r\n title: 'Fire'\r\n});\r\n\r\nvar firedLabel = Ti.UI.createLabel({\r\n top: 300,\r\n right: 25,\r\n text: 'Fired: ' + 0\r\n});\r\n\r\nadd.addEventListener('click', function () {\r\n count++;\r\n countLabel.text = 'Added: ' + count;\r\n Ti.App.addEventListener('app:test', listener);\r\n});\r\n\r\nremove.addEventListener('click', function () {\r\n count--;\r\n countLabel.text = 'Added: ' + count;\r\n Ti.App.removeEventListener('app:test', listener);\r\n});\r\n\r\nfire.addEventListener('click', function () {\r\n fired = 0;\r\n firedLabel.text = 'Fired: ' + fired;\r\n Ti.App.fireEvent('app:test');\r\n});\r\n\r\nwin.add(countLabel);\r\nwin.add(remove);\r\nwin.add(add);\r\nwin.add(firedLabel);\r\nwin.add(fire);\r\n\r\nwin.open();\r\n{code} ", "attachment": [], "flagged": false, "summary": "Adding the same event listener twice should not be allowed", "creator": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "subtasks": [], "reporter": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "environment": "SDK 3.1.3.RC (updated version)\r\nAndroid 4.1.2 on Samsung Galaxy S2\r\niOS 7 GM on iPhone 4S", "comment": { "comments": [ { "id": "271697", "author": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "Some info on why this was resolved as {{Not Our Bug}} would be appreciated.", "updateAuthor": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2013-09-18T08:14:05.000+0000", "updated": "2013-09-18T08:14:05.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }