Uploaded image for project: 'Alloy'
  1. Alloy
  2. ALOY-867

dataTranform executes twice in Alloy using sql data source

    Details

    • Sprint:
      2013 Sprint 23

      Description

      Started via developer question:

      http://developer.appcelerator.com/question/157503/alloy-collection-transform-executes-twice-per-row

      I used the sample app here:

      https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload

      and altered 2 files.

      index.xml - added the dataTransform call and removed the dataFunction call:

      <Alloy>
          <Window>
              <Label id="title" onClick="addTestFighter">Fighters</Label>
              <TableView id="table" dataCollection="fighters" onClick="showId" dataTransform="transformData">
                  <Require src="row"/>
              </TableView>
          </Window>
      </Alloy>
      

      index.js - added a simple transformData function that just spits out the ID

      var fighters = Alloy.Collections.fighters;
      var counter = 1;
       
      function showId(e) {
          if (e.row.model) {
              alert(e.row.model);
          }
      }
       
      function addTestFighter(e) {
          // create the test fighter model
          var model = Alloy.createModel('fighters', {
              name: 'Name ' + counter,
              nickname: 'Nickname ' + counter
          });
          counter++;
       
          // add model to the collection and save it to sqlite
          fighters.add(model);
          model.save();
       
          // let's refresh so we can see the ids coming from the
          // autoincrement field in the sqlite database in the
          // row click alerts
          fighters.fetch();
      }
       
      function transformData(model) {
          var attrs = model.toJSON();
          Ti.API.info('attrs: '+ attrs.id);
          return attrs;
      }
       
      fighters.fetch();
       
      $.index.open();
      

      When I run this I can see the transform function called twice:

      [INFO][TiAPI   ( 2072)]  attrs: 1
      [INFO][TiAPI   ( 2072)]  attrs: 2
      [INFO][TiAPI   ( 2072)]  attrs: 3
      [INFO][TiAPI   ( 2072)]  attrs: 4
      [INFO][TiAPI   ( 2072)]  attrs: 5
      [INFO][TiAPI   ( 2072)]  attrs: 6
      [INFO][TiAPI   ( 2072)]  attrs: 7
      [INFO][TiAPI   ( 2072)]  attrs: 8
      [INFO][TiAPI   ( 2072)]  attrs: 9
      [INFO][TiAPI   ( 2072)]  attrs: 10
      [INFO][dalvikvm-heap( 2072)] Grow heap (frag case) to 3.390MB for 635808-byte allocation
      [INFO][TiAPI   ( 2072)]  attrs: 1
      [INFO][TiAPI   ( 2072)]  attrs: 2
      [INFO][TiAPI   ( 2072)]  attrs: 3
      [INFO][TiAPI   ( 2072)]  attrs: 4
      [INFO][TiAPI   ( 2072)]  attrs: 5
      [INFO][TiAPI   ( 2072)]  attrs: 6
      [INFO][TiAPI   ( 2072)]  attrs: 7
      [INFO][TiAPI   ( 2072)]  attrs: 8
      [INFO][TiAPI   ( 2072)]  attrs: 9
      [INFO][TiAPI   ( 2072)]  attrs: 10
      

      Note - this seems to only happen when using the SQL data source. If you use the in memory data structure it doesn't happen. Eg this seems to work fine:

      https://github.com/appcelerator/alloy/tree/master/test/apps/models/binding_dataFunction

        Attachments

          Activity

            People

            • Assignee:
              tlukasavage Tony Lukasavage
              Reporter:
              kolchy Karl Kopp
            • Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration