[ALOY-552] Alloy generates erroneous code to set an event listener inside a repetition view
GitHub Issue
n/a
Type
Bug
Priority
High
Status
Closed
Resolution
Fixed
Resolution Date
2013-03-18T19:27:39.000+0000
Affected Version/s
n/a
Fix Version/s
Alloy 1.1.0, 2013 Sprint 06
Components
Runtime, XML
Labels
alloy, alloy-generate, qe-port
Reporter
Andrey Chirikba
Assignee
Tony Lukasavage
Created
2013-03-12T11:28:58.000+0000
Updated
2013-05-01T14:56:29.000+0000
Description
When using XML markup to set an event listener on an element inside a repetition view, Alloy generates erroneous code. The auto-generated object ids are not counted correctly, which leads to using one id to create an object and another id to try and set an event listener on it. Consider this snippet:
It is translated to the below:
var __alloyId8 = function(e) {
var models = Alloy.Collections.document.models, children = $.__views.__alloyId4.children;
for (var d = children.length - 1; d >= 0; d--) $.__views.__alloyId4.remove(children[d]);
len = models.length;
for (var i = 0; i < len; i++) {
var __alloyId5 = models[i];
__alloyId5.__transform = {};
var __alloyId7 = Ti.UI.createLabel({
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: typeof __alloyId5.__transform.id != "undefined" ? __alloyId5.__transform.id : __alloyId5.get("id"),
id: "__alloyId6"
});
$.__views.__alloyId4.add(__alloyId7);
idClicked ? $.__views.__alloyId6.addEventListener("click", idClicked) : __defers["$.__views.__alloyId6!click!idClicked"] = !0;
}
};
Notice the __alloyId6 id is used to try and set the event listener instead of __alloyId7 that was actually defined.
This leads to a run-time crash. Please see a testcase attached.
Verified as fixed. Alloy version 1.1.0-cr CLI version 3.1.0-cr Android and iOS Closing.