Titanium JIRA Archive
Alloy (ALOY)

[ALOY-691] Alloys Data Binding feature does not respect platform property

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-05-22T15:50:18.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.4.0
ComponentsModels
Labelsalloy, qe-testadded
ReporterJick Steen
AssigneeTim Poulsen
Created2013-06-05T16:12:08.000+0000
Updated2014-05-23T17:32:41.000+0000

Description

Hi, when using data binding on an element limited to a specific platform, the data function will be created twice. After compiling the example below you will notice the created resource contains two render functions. The render function for iOS and MobileWeb overwrites the function for Android. Calling $.destroy() might break on iOS because the Android related collection is not defined. Link to Q&A: http://developer.appcelerator.com/question/153195/alloys-data-binding-feature-does-not-respect-platform-property View:
<Alloy>
    <Collection src="test" />
    <Window id="index">
        <View id="content" dataCollection="test" dataFunction="render" platform="android">
            <View></View>
        </View>
        <TableView id="content" dataCollection="test" dataFunction="render" platform="ios,mobileweb">
            <TableViewRow>
                <View></View>
            </TableViewRow>
        </TableView>
    </Window>
</Alloy>
Controller:
$.index.open(); 
 
render();
 
$.destroy();
Model:
exports.definition = {
 
  configuration : {
    "columns": {
      "username":"string"
    },
    "adapter": {
      "type": "sql",
      "collection_name": "test"
    },
  },
 
  extendModel: function(Model) {
 
    _.extend(Model.prototype, {});
 
    return Model;
  },
 
  extendCollection: function(Collection) {
 
    _.extend(Collection.prototype, {});
 
    return Collection;
  }
}

Comments

  1. Tim Poulsen 2014-02-19

    PR: https://github.com/appcelerator/alloy/pull/339 Functional test: Using either the sample code provided in the ticket above or in the test app ALOY-691, build the app. Only one copy of render() is included in the generated code.
  2. Tony Lukasavage 2014-02-26

    PR: https://github.com/appcelerator/alloy/pull/342
  3. Lokesh Choudhary 2014-05-15

    Reopening as for android I am seeing two copies of render() in the generated code. On iOS & mobileweb, only one copy of render() is seen. Code generated for android:
       function Controller() {
           function render(e) {
               if (e && e.fromAdapter) return;
               render.opts || {};
               var models = __alloyId5.models;
               var len = models.length;
               var children = $.__views.content.children;
               for (var d = children.length - 1; d >= 0; d--) $.__views.content.remove(children[d]);
               for (var i = 0; len > i; i++) {
                   var __alloyId2 = models[i];
                   __alloyId2.__transform = {};
                   var __alloyId4 = Ti.UI.createView({});
                   $.__views.content.add(__alloyId4);
               }
           }
           function render(e) {
               if (e && e.fromAdapter) return;
               render.opts || {};
               var models = __alloyId11.models;
               var len = models.length;
               var rows = [];
               for (var i = 0; len > i; i++) {
                   var __alloyId6 = models[i];
                   __alloyId6.__transform = {};
                   var __alloyId8 = Ti.UI.createTableViewRow({});
                   rows.push(__alloyId8);
                   var __alloyId10 = Ti.UI.createView({});
                   __alloyId8.add(__alloyId10);
               }
               $.__views.content.setData(rows);
           }
       
    Environment: Appc Studio : 3.3.0.201405121247 Ti SDK : 3.3.0.v20140514163013 Mac OSX : 10.8.5 Alloy : 1.4.0-alpha CLI - 3.3.0-dev Nexus 5 - android 4.4.2
  4. Tim Poulsen 2014-05-19

    New PR https://github.com/appcelerator/alloy/pull/401 submitted and merged
  5. Tim Poulsen 2014-05-21

    Reopening because my last implementation didn't work properly when an element was tagged to support multiple platforms.
  6. Tim Poulsen 2014-05-22

    New PR https://github.com/appcelerator/alloy/pull/410 Merged to 1_4_X and master Properly prevents the processing of children (e.g. TableViewRows) of tags not for the current platform (e.g. TableView). Test app https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-691
  7. Federico Casali 2014-05-22

    Verified fixed and working as expected with the latest sample code and fix. Closing. TiSDK 3.3.0.v20140522110830 Alloy 1.4.0-alpha4 Appcelerator Studio 3.3.0.201405211748 CLI 3.3.0-alpha5 iOS Compiled code :
       function render(e) {
               if (e && e.fromAdapter) return;
               render.opts || {};
               var models = __alloyId7.models;
               var len = models.length;
               var rows = [];
               for (var i = 0; len > i; i++) {
                   var __alloyId2 = models[i];
                   __alloyId2.__transform = {};
                   var __alloyId4 = Ti.UI.createTableViewRow({});
                   rows.push(__alloyId4);
                   var __alloyId6 = Ti.UI.createView({});
                   __alloyId4.add(__alloyId6);
               }
               $.__views.content.setData(rows);
           }
       
    Android Compiled code:
         function render(e) {
               if (e && e.fromAdapter) return;
               render.opts || {};
               var models = __alloyId5.models;
               var len = models.length;
               var children = $.__views.content.children;
               for (var d = children.length - 1; d >= 0; d--) $.__views.content.remove(children[d]);
               for (var i = 0; len > i; i++) {
                   var __alloyId2 = models[i];
                   __alloyId2.__transform = {};
                   var __alloyId4 = Ti.UI.createView({});
                   $.__views.content.add(__alloyId4);
               }
           }
       

JSON Source