Details
-
Type:
Story
-
Status: Open
-
Priority:
High
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: Release 10.1.0
-
Component/s: TiAPI
-
Labels:
-
Epic Link:
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.
i.e. We often have a single listener on Ti.UI.Window#close() where we want to clean up after the windows is closed. Compare:
win.addEventListener('close', function listener (e) { |
win.removeEventListener('close', listener); // clean up this callback listener |
// do whatever other cleanup we want |
});
|
win.close();
|
|
// versus
|
|
window.close(e => {
|
// do whatever other cleanup we want |
});
|
It 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).
Note that this would also position us well to add "shims" to convert these methods calls into Promise-based APIs at the JS level.
win.close().then(e => {
|
// do whatever other cleanup we want |
});
|
// or...
|
const closeEvent = await win.close();
|
// do whatever other cleanup we want |
Attachments
Issue Links
- is cloned into
-
TIMOB-28340 TiAPI: Return Promise for Ti.UI.Window open() and close()
-
- Resolved
-
- relates to
-
TIMOB-25536 TiAPI: Deprecate Ti global namespace, move to require/import based API's
-
- Open
-
-
TIMOB-24549 TiAPI: Add support for Promises
-
- Resolved
-
-
TIMOB-27711 TiAPI: Add state querying methods to UI components
-
- Closed
-