{ "id": "103966", "key": "TIMOB-13338", "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": "2012-10-26T09:44:19.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "API", "Titanium", "listeners" ], "versions": [], "issuelinks": [ { "id": "27333", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "112190", "key": "TIMOB-13365", "fields": { "summary": "Ti API: Make the templating system used for ListView general purpose", "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" } }, "priority": { "name": "Low", "id": "4" }, "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false } } } } ], "assignee": null, "updated": "2018-02-28T20:03:30.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": "10224", "name": "TiAPI", "description": "This component is used for cross-platform API work. Specifications are most likely to use this component." } ], "description": "for example, it would be nice to have a method like Titanium.Proxy.addEventListeners( { } );\r\n\r\n{code}\r\nvar self = Ti.UI.createWindow({\r\n\t\t\r\n\t}); \r\n\r\n\r\nself.addEventListeners(\r\n\t{\r\n\t blur : function(e) { Ti.API.warn( JSON.stringify (e) ) } ,\r\n\t\r\n\tfocus: function(e) { Ti.API.warn( JSON.stringify (e)) },\r\n\r\n\tmyEvent : function(e) { Ti.API.warn( JSON.stringify (e)) },\r\n\t}\r\n\r\n\r\n);\r\n{code}\r\nto be clear I know, this can be done in Javascript ( but this means adding a method to Titanium.Proxy ) , and the idea here is not to call addEventListener in a loop but rather cross the bridge only once receiving a NSDictionary to transform callbacks in KrollCallbacks ( something like applyProperties()).\r\n\r\n\r\nfor IOS my first try was to do : \r\n{code}\r\n-(void)addEventListeners:(id)args\r\n{\r\n \r\n ENSURE_SINGLE_ARG(args, NSDictionary);\r\n \r\n for (NSString * currentKey in args)\r\n {\r\n KrollCallback* currentListener = [args objectForKey:currentKey];\r\n ENSURE_TYPE(currentListener,KrollCallback);\r\n \r\n [self addEventListener: [NSArray arrayWithObjects:currentKey, currentListener, nil] ];\r\n \r\n }\r\n \r\n}\r\n{code}\r\nThis seems to work, but i'm safe to do that ?\r\n\r\n\r\n\r\n\r\n\r\n-Moreover would it be possible to pass a Dictionary of eventListeners in the Ti factory methods ?\r\n{code}\r\nTi.UI.createXXX({\r\npropertyX : value\r\n...\r\neventListeners : { .... } // is this possible for UI events ? custom events ? \r\n\r\n})\r\n{code}\r\nIn some case , this could ensure that the listeners are registered before the events occur ( Ti.UI.Window events for example )\r\n\r\n\r\n\r\n\r\n- I saw that Alloy implement the on(..) off(..) method with event listeners, so another solution could be to use the same syntax in the Proxy create method:\r\n{code}\r\nTi.UI.createXXX({\r\npropertyX : value\r\n...\r\nonClick = function(){}\r\n...\r\n\r\n})\r\n\r\n{code}\r\n\r\n", "attachment": [], "flagged": false, "summary": "Ti API: implement features to add several listeners to a proxy in one call ", "creator": { "name": "vince", "key": "vince", "displayName": "Vincent ", "active": true, "timeZone": "Europe/Paris" }, "subtasks": [], "reporter": { "name": "vince", "key": "vince", "displayName": "Vincent ", "active": true, "timeZone": "Europe/Paris" }, "environment": "Titanium API", "comment": { "comments": [ { "id": "245689", "author": { "name": "ivan.skugor", "key": "ivan.skugor", "displayName": "Ivan Skugor", "active": true, "timeZone": "Europe/Amsterdam" }, "body": "Maybe array of event listeners would be better since there can be multiple event listeners per event type.\r\n\r\n\r\nFor example:\r\n\r\n{code}\r\nself.addEventListeners([\r\n { click : function(e) { Ti.API.warn( JSON.stringify (e) ) } },\r\n \r\n { click: function(e) { Ti.API.warn( JSON.stringify (e)) } }, \r\n \r\n { myEvent : function(e) { Ti.API.warn( JSON.stringify (e)) } }\r\n]);\r\n{code}", "updateAuthor": { "name": "ivan.skugor", "key": "ivan.skugor", "displayName": "Ivan Skugor", "active": true, "timeZone": "Europe/Amsterdam" }, "created": "2013-04-04T08:56:41.000+0000", "updated": "2013-04-04T08:56:41.000+0000" }, { "id": "245710", "author": { "name": "bhughes", "key": "bhughes", "displayName": "Bryan Hughes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "We have been considering making the templating system that ListView uses available for all controls, and this dovetails nicely since templates already support listing multiple event listeners. Even if we don't make templates general purpose, this call should probably conform to the ListView template spec for uniformity's sake.", "updateAuthor": { "name": "bhughes", "key": "bhughes", "displayName": "Bryan Hughes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-04-04T15:29:26.000+0000", "updated": "2013-04-04T15:29:26.000+0000" }, { "id": "295649", "author": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "body": "We will revisit this at a later point when there is significant customer requests.", "updateAuthor": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-03-04T22:40:01.000+0000", "updated": "2014-03-04T22:40:01.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }