{ "id": "121409", "key": "ALOY-867", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "15403", "description": "Alloy 1.3.0", "name": "Alloy 1.3.0", "archived": false, "released": true, "releaseDate": "2013-12-20" }, { "id": "15754", "description": "2013 Sprint 23", "name": "2013 Sprint 23", "archived": true, "released": true, "releaseDate": "2013-11-15" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-11-15T22:23:42.000+0000", "created": "2013-10-20T05:32:40.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "alloy", "dataFilter", "qe-port" ], "versions": [], "issuelinks": [], "assignee": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2017-10-25T15:36:23.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "12329", "name": "Runtime", "description": "Generic bucket for uncategorized runtime issues" } ], "description": "Started via developer question:\r\n\r\nhttp://developer.appcelerator.com/question/157503/alloy-collection-transform-executes-twice-per-row\r\n\r\nI used the sample app here:\r\n\r\nhttps://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload\r\n\r\nand altered 2 files.\r\n\r\nindex.xml - added the dataTransform call and removed the dataFunction call:\r\n{code}\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n{code}\r\n\r\nindex.js - added a simple transformData function that just spits out the ID\r\n\r\n{code}\r\nvar fighters = Alloy.Collections.fighters;\r\nvar counter = 1;\r\n \r\nfunction showId(e) {\r\n if (e.row.model) {\r\n alert(e.row.model);\r\n }\r\n}\r\n \r\nfunction addTestFighter(e) {\r\n // create the test fighter model\r\n var model = Alloy.createModel('fighters', {\r\n name: 'Name ' + counter,\r\n nickname: 'Nickname ' + counter\r\n });\r\n counter++;\r\n \r\n // add model to the collection and save it to sqlite\r\n fighters.add(model);\r\n model.save();\r\n \r\n // let's refresh so we can see the ids coming from the\r\n // autoincrement field in the sqlite database in the\r\n // row click alerts\r\n fighters.fetch();\r\n}\r\n \r\nfunction transformData(model) {\r\n var attrs = model.toJSON();\r\n Ti.API.info('attrs: '+ attrs.id);\r\n return attrs;\r\n}\r\n \r\nfighters.fetch();\r\n \r\n$.index.open();\r\n{code}\r\n\r\nWhen I run this I can see the transform function called twice:\r\n\r\n{code}\r\n[INFO][TiAPI ( 2072)] attrs: 1\r\n[INFO][TiAPI ( 2072)] attrs: 2\r\n[INFO][TiAPI ( 2072)] attrs: 3\r\n[INFO][TiAPI ( 2072)] attrs: 4\r\n[INFO][TiAPI ( 2072)] attrs: 5\r\n[INFO][TiAPI ( 2072)] attrs: 6\r\n[INFO][TiAPI ( 2072)] attrs: 7\r\n[INFO][TiAPI ( 2072)] attrs: 8\r\n[INFO][TiAPI ( 2072)] attrs: 9\r\n[INFO][TiAPI ( 2072)] attrs: 10\r\n[INFO][dalvikvm-heap( 2072)] Grow heap (frag case) to 3.390MB for 635808-byte allocation\r\n[INFO][TiAPI ( 2072)] attrs: 1\r\n[INFO][TiAPI ( 2072)] attrs: 2\r\n[INFO][TiAPI ( 2072)] attrs: 3\r\n[INFO][TiAPI ( 2072)] attrs: 4\r\n[INFO][TiAPI ( 2072)] attrs: 5\r\n[INFO][TiAPI ( 2072)] attrs: 6\r\n[INFO][TiAPI ( 2072)] attrs: 7\r\n[INFO][TiAPI ( 2072)] attrs: 8\r\n[INFO][TiAPI ( 2072)] attrs: 9\r\n[INFO][TiAPI ( 2072)] attrs: 10\r\n{code}\r\n\r\nNote - 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:\r\n\r\nhttps://github.com/appcelerator/alloy/tree/master/test/apps/models/binding_dataFunction", "attachment": [], "flagged": false, "summary": "dataTranform executes twice in Alloy using sql data source", "creator": { "name": "kolchy", "key": "kolchy", "displayName": "Karl Kopp", "active": true, "timeZone": "Australia/Sydney" }, "subtasks": [], "reporter": { "name": "kolchy", "key": "kolchy", "displayName": "Karl Kopp", "active": true, "timeZone": "Australia/Sydney" }, "environment": "Window 8, Titanium 3.1.3, Alloy 1.2.2, running on Android 4.2 on HTC One", "closedSprints": [ { "id": 22, "state": "closed", "name": "2013 Sprint 23", "startDate": "2013-11-04T23:11:21.521Z", "endDate": "2013-11-16T04:11:00.000Z", "completeDate": "2013-11-21T16:47:18.248Z" } ], "comment": { "comments": [ { "id": "278240", "author": { "name": "pedrevans", "key": "pedrevans", "displayName": "Peter Evans", "active": true, "timeZone": "Europe/Berlin" }, "body": "I suspect that the transform is being called once for each model attribute, not once per model. This is what my logging shows. I have a model with 10 attributes and the transform is being called 10 times. I'm using sqlrest too.", "updateAuthor": { "name": "pedrevans", "key": "pedrevans", "displayName": "Peter Evans", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-11-05T19:59:46.000+0000", "updated": "2013-11-05T19:59:46.000+0000" }, { "id": "278571", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This fix was a combination of a fix for the fetch event firing too many times, but also adding some \"silent\" flags to the save() and add() calls to ensure binding is not triggered too many times. \r\n\r\nPR: https://github.com/appcelerator/alloy/pull/271\r\ntest app: https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload\r\n\r\nFunctional test (run for ios)\r\n\r\n# Run the app\r\n# Ensure that the log shows one message from the {{dataTransform}} function for each model represented in the UI. Only one message per model.\r\n# Click the title bar. This should add a new model to the collection and add it to the end of the list in the UI.\r\n# Ensure that this event generated only one message from the {{dataTransform}} function for each model represented in the UI, exactly like when you initially started.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-11-07T03:16:57.000+0000", "updated": "2013-11-07T03:16:57.000+0000" }, { "id": "279848", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Re-opening due to the fact that this fix caused data binding UI updates not to fire in some cases. Investigating.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-11-15T20:38:37.000+0000", "updated": "2013-11-15T20:38:37.000+0000" }, { "id": "279888", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "commit: https://github.com/appcelerator/alloy/commit/5645fc7d4a2852ef3ac6fb789e25f2de52fa8d38\r\n\r\nTest the same as originally noted. In addition also run the following test app:\r\n\r\nhttps://github.com/appcelerator/alloy/tree/master/test/apps/models/todo\r\n\r\n# Ensure that it runs without compile or runtime errors.\r\n# Ensure that when you add, check, or delete items that they are always surrounded by square brackets, which are added in the dataTransform method. Prior to this commit, some of these operations would work, but not show the square brackets around the items.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-11-15T22:23:42.000+0000", "updated": "2013-11-15T22:23:42.000+0000" }, { "id": "282314", "author": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Verified fixed.\n\nTiSDK 3.2.0.v20131127194046\nCLI 3.2.0-beta\nAlloy 1.3.0-beta\n\nClosing.", "updateAuthor": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-04T00:28:48.000+0000", "updated": "2013-12-04T00:28:48.000+0000" }, { "id": "429564", "author": { "name": "koryonb", "key": "koryonb", "displayName": "Benjamin Koryon", "active": true, "timeZone": "America/New_York" }, "body": "I'm experiencing a similar issue, where the dataTransform attribute executes every time for each item in the collection. Logging in the dataTransform function proves the fact that it's executing for each item in the collection. \r\n\r\nHere's my current setup: \r\n\r\nOperating System\r\n Name = Mac OS X\r\n Version = 10.12.6\r\n Architecture = 64bit\r\n # CPUs = 8\r\n Memory = 16.0GB\r\n\r\nNode.js\r\n Node.js Version = 6.11.4\r\n npm Version = 3.10.10\r\n\r\nAppcelerator CLI\r\n Installer = 4.2.9\r\n Core Package = 6.2.4\r\n\r\nTitanium CLI\r\n CLI Version = 5.0.14\r\n node-appc Version = 0.2.41\r\n\r\nTitanium SDKs\r\n 6.2.2.GA\r\n Version = 6.2.2\r\n Install Location = \r\n Platforms = iphone, android, mobileweb\r\n git Hash = 42c7196\r\n git Timestamp = 9/19/2017 23:07\r\n node-appc Version = 0.2.43\r\n", "updateAuthor": { "name": "koryonb", "key": "koryonb", "displayName": "Benjamin Koryon", "active": true, "timeZone": "America/New_York" }, "created": "2017-10-25T15:36:23.000+0000", "updated": "2017-10-25T15:36:23.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }