[ALOY-1368] Complex data binding for individual model doesn't work with transform() method
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-03-28T18:11:14.000+0000 |
Affected Version/s | alloy 1.7.35 |
Fix Version/s | alloy 1.8.3, Release 5.2.2 |
Components | Models, XML |
Labels | n/a |
Reporter | Fokke Zandbergen |
Assignee | Fokke Zandbergen |
Created | 2016-03-16T12:22:48.000+0000 |
Updated | 2016-03-31T22:44:06.000+0000 |
Description
The complex data binding introduced by ALOY-443 does not work if the model has a
transform()
method:
<Alloy>
<Model src="user" />
<Window>
<Label title="{user.foo}" />
<Label title="the {user.foo}" />
<Label title="{user.foo} - {user.bar}" />
</Window>
</Alloy>
Compiles to:
var __alloyId13 = function() {
$.__alloyId2.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("<%=user.foo%>", {
user: Alloy.Models.user.toJSON()
});
$.__alloyId3.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("the <%=user.foo%>", {
user: Alloy.Models.user.toJSON()
});
$.__alloyId4.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("<%=user.foo%> - <%=user.bar%>", {
user: Alloy.Models.user.toJSON()
});
};
So, if the model has a transform()
method all three labels will only show the value of the foo attribute.
The correct code should be:
var __alloyId13 = function() {
var transformed = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform() : Alloy.Models.user.toJSON();
$.__alloyId2.title = _.template("<%=user.foo%>", {
user: transformed
});
$.__alloyId3.title = _.template("the <%=user.foo%>", {
user: transformed
});
$.__alloyId4.title = _.template("<%=user.foo%> - <%=user.bar%>", {
user: transformed
});
};
PR: https://github.com/appcelerator/alloy/pull/767
Updated PR to only call
transform()
once.New PR to include ALOY-1474: https://github.com/appcelerator/alloy/pull/776
PR merged.
Additionally, this also fixed that using strings before the first occurrence of a placeholder caused syntax errors like:
Verified fixed, using: MacOS 10.11.4 (15E65) Studio 4.5.0.201602170821 Ti SDK 5.2.2.v20160328141205 Appc NPM 4.2.5-1 Appc CLI 5.2.2-3 Alloy 1.8.5 Xcode 7.3 (7D175) Complex data binding for models using transform are working as expected. Tested using the project in ALOY-1474 as well as custom apps using a model with a transform function. Code generated matches the form of the correct code in ticket description.