Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2714] Alloy on/off/trigger for View is not returning the View itself

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionWon't Fix
Resolution Date2013-02-07T01:24:39.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAlloy
Labelsn/a
ReporterMing Liu
AssigneeMauro Parra-Miranda
Created2013-01-30T18:20:25.000+0000
Updated2016-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; };

Comments

  1. Tony Lukasavage 2013-02-07

    As of Alloy 1.0.0, Backbone eventing will be removed from Titanium proxies for performance reasons. Details can be found in ALOY-455.

JSON Source