{ "id": "174615", "key": "TIMOB-27710", "fields": { "issuetype": { "id": "7", "description": "gh.issue.story.desc", "name": "Story", "subtask": false }, "sprint": { "id": 1231, "state": "active", "name": "2021 Sprint 21", "startDate": "2021-10-07T16:05:18.981Z", "endDate": "2021-10-21T16:05:00.000Z", "originBoardId": 219 }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "21249", "name": "Release 10.2.0", "archived": false, "released": false } ], "resolution": null, "resolutiondate": null, "created": "2020-01-08T15:04:34.000+0000", "epic": { "id": 172628, "key": "TIMOB-26570", "name": "Node Compatibility", "summary": "Node compatibility and developer experience", "color": { "key": "color_3" }, "done": false }, "priority": { "name": "High", "id": "2" }, "labels": [ "engSchedule" ], "versions": [], "issuelinks": [ { "id": "59171", "type": { "id": "10001", "name": "Cloners", "inward": "is cloned into", "outward": "is cloned from" }, "inwardIssue": { "id": "176035", "key": "TIMOB-28340", "fields": { "summary": "TiAPI: Return Promise for Ti.UI.Window open() and close()", "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" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "7", "description": "gh.issue.story.desc", "name": "Story", "subtask": false } } } }, { "id": "59313", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "175896", "key": "TIMOB-28279", "fields": { "summary": "TiAPI: Return Promises for async APIs", "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": "Medium", "id": "3" }, "issuetype": { "id": "6", "description": "gh.issue.epic.desc", "name": "Epic", "subtask": false } } } }, { "id": "58184", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "174726", "key": "TIMOB-27763", "fields": { "summary": "iOS: “don’t allow” in push notification dialog triggering success callback", "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" } }, "priority": { "name": "None", "id": "6" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } }, { "id": "58070", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "170383", "key": "TIMOB-25536", "fields": { "summary": "TiAPI: Deprecate Ti global namespace, move to require/import based API's", "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": "High", "id": "2" }, "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false } } } }, { "id": "58119", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "166898", "key": "TIMOB-24549", "fields": { "summary": "TiAPI: Add support for Promises", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "6", "description": "gh.issue.epic.desc", "name": "Epic", "subtask": false } } } }, { "id": "58069", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "174617", "key": "TIMOB-27711", "fields": { "summary": "TiAPI: Add state querying methods to UI components", "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" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "7", "description": "gh.issue.story.desc", "name": "Story", "subtask": false } } } } ], "assignee": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "updated": "2021-10-07T16:04:52.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": "We have a number of basic operations that rely on event listener based usage to handle notifying when the operation is \"complete\". While this works, it can lead to a lot of boilerplate code for hanging simple one-time callback logic when the operation is complete.\r\n\r\ni.e. We often have a single listener on Ti.UI.Window#close() where we want to clean up after the windows is closed. Compare:\r\n{code:javascript}\r\nwin.addEventListener('close', function listener (e) {\r\n win.removeEventListener('close', listener); // clean up this callback listener\r\n // do whatever other cleanup we want\r\n});\r\nwin.close();\r\n\r\n// versus\r\n\r\nwindow.close(e => {\r\n // do whatever other cleanup we want\r\n});\r\n{code}\r\n\r\nIt would be good to review our APIs and the events we fire and see if they are explicitly tied to methods called by the developer - and if so, provide optional callback functions as the final arguments so that developers could use a more Node.JS style usage and streamline cases where you only expect a single listener/callback (though for backwards compatibility and for supporting multiple listeners we shoulder retain the event firing as well).\r\n\r\nNote that this would also position us well to add \"shims\" to convert these methods calls into Promise-based APIs at the JS level.\r\n{code:javascript}\r\nwin.close().then(e => {\r\n // do whatever other cleanup we want\r\n});\r\n// or...\r\nconst closeEvent = await win.close();\r\n// do whatever other cleanup we want\r\n{code}", "attachment": [], "flagged": false, "summary": "TiAPI: Support optional callback functions for async methods that typically fire events", "creator": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "environment": null, "comment": { "comments": [ { "id": "453505", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Potential targets:\r\n- {{Ti.UI.Window#close()}}\r\n- {{Ti.UI.Window#open()}}\r\n- {{Ti.UI.View#hide()}}\r\n- {{Ti.UI.View#show()}}\r\n- {{Ti.UI.View}} subclasses with {{blur()}} and {{focus()}} methods (i.e. TextField, SearchBar, TextArea)\r\n- {{Ti.UI.RefreshControl#beginRefreshing()}}\r\n- {{Ti.UI.RefreshControl#endRefreshing()}}\r\n- {{Titanium.UI.ImageView#pause()}}\r\n- {{Titanium.UI.ImageView#resume()}}\r\n- {{Titanium.UI.ImageView#start()}}\r\n- {{Titanium.UI.ImageView#stop()}}\r\n\r\nNote that {{Ti.UI.View#animate()}} already supports an optional callback for this exact same use-case/style.\r\n\r\nAlso note that in all these cases, these methods are already operating asynchronously so behavior isn't changing/breaking (form sync to async). They simply were typically firing off events when the operation finished.", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2020-01-08T15:40:19.000+0000", "updated": "2020-01-08T15:40:19.000+0000" }, { "id": "453506", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Faintly related to TIMOB-25536 - Basically I think Gary's ti.es6 project could potentially be another means of doing the callback -> Promise API wrapping, since I think he's sort of baked that in to the shim generation? cc [~gmathews]", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2020-01-08T15:52:53.000+0000", "updated": "2020-01-08T15:52:53.000+0000" }, { "id": "454210", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Another potential method: {{Ti.App.iOS.registerUserNotificationSettings}} - users have to register an event listener 'usernotificationsettings' to handle the success/failure of this method call async. This feels ripe for a callback/Promise.", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2020-02-12T14:38:07.000+0000", "updated": "2020-02-12T14:38:07.000+0000" }, { "id": "458676", "author": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Linking to a list of potential methods of interest https://github.com/appcelerator/titanium_mobile/pull/10554#issuecomment-737611822", "updateAuthor": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2021-05-12T22:50:34.000+0000", "updated": "2021-05-12T22:50:34.000+0000" } ], "maxResults": 7, "total": 7, "startAt": 0 } } }