[ALOY-841] Add an `once` function for call-once global events
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | n/a |
| Status | Closed |
| Resolution | Won't Fix |
| Resolution Date | 2014-01-20T22:07:04.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Builtins |
| Labels | alloy |
| Reporter | Mauro Parra-Miranda |
| Assignee | Tony Lukasavage |
| Created | 2013-10-07T08:28:38.000+0000 |
| Updated | 2014-02-28T23:57:15.000+0000 |
Description
I use this function to avoid global events not releasing local objects:
Alloy.Globals.once = function(event, cb) {
var _cb = function() {
cb.apply(this, arguments);
// Clean up
Ti.App.removeEventListener(event, _cb);
};
Ti.App.addEventListener(event, _cb);
};
Come handy when there is UI/async call interaction allowing to preserve a workflow (instead of continuation callbacks).
Would be meaningful to add to Alloy eg Alloy.once("an:app:event", doOnceCb)?
Alloy.Globalsis not meant to be an eventing interface, and I don't want to add code like this that will appear to make it so. This seems much better suited as an external library, or this simple implementation by the developer.