[AC-2714] Alloy on/off/trigger for View is not returning the View itself
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2013-02-07T01:24:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy |
Labels | n/a |
Reporter | Ming Liu |
Assignee | Mauro Parra-Miranda |
Created | 2013-01-30T18:20:25.000+0000 |
Updated | 2016-03-08T07:41:49.000+0000 |
Description
As per API of backbonejs, on/off/trigger return 'this' so that calls may be chained.
http://backbonejs.org/docs/backbone.html#section-19
This is what's appeared in Alloy.
exports.A = function(t, type, parent) {
_.extend(t, Backbone.Events);
(function() {
var al = t.addEventListener, rl = t.removeEventListener, oo = t.on, of = t.off, tg = t.trigger, cbs = {}, ctx = _.extend({}, Backbone.Events);
if (!al || !rl) return;
t.trigger = function() {
ctx.trigger.apply(ctx, Array.prototype.slice.apply(arguments));
};
t.on = function(e, cb, context) {
var wcb = function(evt) {
try {
_.bind(tg, ctx, e, evt)();
} catch (E) {
Ti.API.error("Error triggering '" + e + "' event: " + E);
}
};
if (!cbs[e]) {
cbs[e] = {};
al(e, wcb);
}
cbs[e][cb] = wcb;
_.bind(oo, ctx, e, cb, context)();
};
t.off = function(e, cb, context) {
var f = cbs[e] ? cbs[e][cb] : null;
if (f) {
_.bind(of, ctx, e, cb, context)();
delete cbs[e][cb];
if (cbs[e].length === 0) {
delete cbs[e];
rl(e, f);
}
f = null;
}
};
})();
return t;
};
As of Alloy 1.0.0, Backbone eventing will be removed from Titanium proxies for performance reasons. Details can be found in ALOY-455.