Titanium JIRA Archive
Alloy (ALOY)

[ALOY-841] Add an `once` function for call-once global events

GitHub Issuen/a
TypeImprovement
Priorityn/a
StatusClosed
ResolutionWon't Fix
Resolution Date2014-01-20T22:07:04.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsBuiltins
Labelsalloy
ReporterMauro Parra-Miranda
AssigneeTony Lukasavage
Created2013-10-07T08:28:38.000+0000
Updated2014-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)?

Comments

  1. Tony Lukasavage 2014-01-20

    Alloy.Globals is 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.

JSON Source