{ "id": "139585", "key": "TIMOB-18039", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2014-11-12T10:36:08.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "TCSupport", "events", "listeners" ], "versions": [ { "id": "16676", "description": "Release 3.4.1", "name": "Release 3.4.1", "archived": false, "released": true, "releaseDate": "2014-11-14" } ], "issuelinks": [], "assignee": null, "updated": "2018-02-28T19:56:00.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "When digging through some source code I discovered Android has a hidden {{once()}} method to add an event listener that only fires once and {{removeAllListeners()}} to remove all listeners to a certain event:\r\n\r\n- http://www.tidev.io/2014/11/10/hidden-event-methods-on-android/\r\n\r\nWhy aren't these methods documented and why not bring these to all platforms?\r\n\r\nBoth have very good use cases to me in almost every app.\r\n\r\nI'd even suggest the following:\r\n\r\n{code}\r\nview.once('click', doClick); // fires once\r\nview.on('click', doClick); // alias for addEventListener()\r\nview.off('click', doClick); // alias for removeEventListener()\r\nview.off('click'); // removes all listeners for the click-event\r\nview.off(); // removes all listeners for any event\r\n{code}\r\n\r\nThe last one would make cleaning up and preventing memory leaks a lot easier as well.", "attachment": [], "flagged": false, "summary": "Add `once`, `on` and `off` to Titanium proxies", "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": "master", "comment": { "comments": [ { "id": "331989", "author": { "name": "mcvendrell", "key": "mcvendrell", "displayName": "Manuel Conde Vendrell", "active": true, "timeZone": "Europe/Madrid" }, "body": "Hi Fokke. \r\n\r\nI my very personal opinion, I don't like it very much the aliases policies. Why you want alias? Why we need to have two or three methods to call the same thing? Noobs, like me one year ago, are lost when they see different code from different people calling different methods to do the same. You ask yourself what this \"new\" methods does different from the original and you need to go to docs to see that... does the same.\r\n\r\nI prefer to have a unique method to do a unique thing (*addEventListener* yes, *addListener*, *on* not). Different case is the *once* method, that does different things.\r\n\r\nExcept for the aliases, will be good to have the rest of functions.", "updateAuthor": { "name": "mcvendrell", "key": "mcvendrell", "displayName": "Manuel Conde Vendrell", "active": true, "timeZone": "Europe/Madrid" }, "created": "2014-11-13T10:04:36.000+0000", "updated": "2014-11-13T10:04:36.000+0000" }, { "id": "331991", "author": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "I agree we shouldn't have too many aliases. However, the name {{once}} comes from BackBone which is also used for Alloy controllers, where people already use {{on}} and {off}}. That plus {{removeEventListener}} no longer does what the name says if you can also remove multiple listeners from one or all events.", "updateAuthor": { "name": "fokkezb", "key": "fokke", "displayName": "Fokke Zandbergen", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2014-11-13T10:25:04.000+0000", "updated": "2014-11-13T10:25:04.000+0000" }, { "id": "399202", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "Proof of Concept: https://github.com/appcelerator/titanium_mobile/compare/master...hansemannn:TIMOB-24038\r\n\r\nAs discussed in TIMOB-24038, they could both coexist like they do in Node JS.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-10-18T07:58:53.000+0000", "updated": "2016-10-18T07:58:53.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }