Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1369] Complex data binding for collection doesn't work with transform

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2016-03-21T19:21:46.000+0000
Affected Version/salloy 1.7.35
Fix Version/salloy 1.8.1, Release 5.2.2
ComponentsModels, XML
Labelsn/a
ReporterFokke Zandbergen
AssigneeFokke Zandbergen
Created2016-03-16T12:55:32.000+0000
Updated2016-03-31T22:39:53.000+0000

Description

The complex data binding introduced by ALOY-443 does not work if the model has a __transform property:
<Alloy>
	<Collection src="user" />
	<Window>
		<TableView dataCollection="user">
			<TableViewRow foo="{a}" bar="the {a}" title="{a} {b}" />
		</TableView>
	</Window>
</Alloy>
Compiles to:
    __alloyId3.__transform = {};
    var __alloyId5 = Ti.UI.createTableViewRow({
      foo: typeof __alloyId3.__transform['a'] !== 'undefined' ? __alloyId3.__transform['a'] : __alloyId3.get('a'),
      bar: typeof __alloyId3.__transform['a'] !== 'undefined' ? __alloyId3.__transform['a'] : the '+__alloyId3.get('
      a ') +',
      title: typeof __alloyId3.__transform['a'] !== 'undefined' ? __alloyId3.__transform['a'] : __alloyId3.get('a') + ' ' + __alloyId3.get('b'),
    });
Which will cause Uglify to crash on the syntax error on line 3. For the other 2 cases the values will always that of a if the model has a __transform property. The correct code should be:
    __alloyId3.__transform = _.isFunction(__alloyId3.transform) ? __alloyId3.transform() : __alloyId3.toJSON();
    var __alloyId5 = Ti.UI.createTableViewRow({
      foo: _.template("<%=a%>", __alloyId3.__transform),
      bar: _.template("<%=the a%>", __alloyId3.__transform),
      title: _.template("<%=a b%>", __alloyId3.__transform)
    });

Comments

  1. Fokke Zandbergen 2016-03-16

    PR: https://github.com/appcelerator/alloy/pull/769
  2. Eric Wieber 2016-03-31

    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 collections using transform are working as expected. Tested using the project in ALOY-1474 as well as custom apps using collections with transform functions. Code generated matches the form of the correct code in ticket description.

JSON Source