{ "id": "86182", "key": "TIMOB-7568", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "12096", "description": "", "name": "Sprint 2012-04", "archived": true, "released": true, "releaseDate": "2012-02-26" }, { "id": "12593", "name": "Release 2.0.0", "archived": false, "released": true, "releaseDate": "2012-03-30" }, { "id": "13070", "description": "Release 1.8 Service Pack 2", "name": "Release 1.8.2", "archived": true, "released": true, "releaseDate": "2012-02-29" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2012-02-13T17:33:13.000+0000", "created": "2012-02-07T14:02:26.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [], "versions": [ { "id": "12593", "name": "Release 2.0.0", "archived": false, "released": true, "releaseDate": "2012-03-30" } ], "issuelinks": [], "assignee": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "updated": "2017-03-16T22:02:54.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": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h1. Feature\r\nAdd support for CommonJS modules to be included in the Titanium Mobile SDK itself, and automatically injected in to the Ti.* namespace.\r\n\r\nh2. Why\r\nWe are now developing several modules to be included in the core distribution that are CommonJS modules. Android has precedent for this (Ti.Yahoo.*), but iOS does not.\r\n\r\nh2. Test\r\nAn example \"test.js\" could be included in Ti SDK:\r\n{code:title=test.js}\r\n(function (Ti, Titanium, exports) {\r\n var Test;\r\n if (Titanium == undefined /* Android */) {\r\n Test = {};\r\n exports.bootstrap = function (TiSDK) {\r\n Ti = Titanium = TiSDK;\r\n return Test;\r\n };\r\n }\r\n else {\r\n Test = exports;\r\n }\r\n \r\n Test.retrieveSuccessLabel = function () {\r\n return Ti.UI.createLabel({\r\n text: 'Success!', textAlign: 'center',\r\n color: '#000'\r\n });\r\n };\r\n})(Ti, Titanium, exports);\r\n{code}\r\n\r\nOn Android it would need to be bootstrapped (to follow the existing convention yahoo.js sets forth) in titanium.js:\r\n{code:title=titanium.js}\r\nTitanium.Test = require('test').bootstrap(Titanium);\r\n{code}\r\nBut on iOS it can simply be require'd normally.\r\n\r\nIt would be used in an app like this:\r\n{code:title=app.js}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor: '#fff'\r\n});\r\nwin.add(Ti.Test.retrieveSuccessLabel());\r\nwin.open();\r\n{code}", "attachment": [], "flagged": false, "summary": "iOS: Using CommonJS Modules in Core Ti SDK", "creator": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "environment": null, "comment": { "comments": [ { "id": "182346", "author": { "name": "ngupta", "key": "ngupta", "displayName": "Neeraj Gupta", "active": true, "timeZone": "America/Los_Angeles" }, "body": "We need this support to integrate ACS CommonJS module.", "updateAuthor": { "name": "ngupta", "key": "ngupta", "displayName": "Neeraj Gupta", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-02-07T22:43:06.000+0000", "updated": "2012-02-07T22:43:06.000+0000" }, { "id": "182374", "author": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "body": "PR opened for one solution:\r\nhttps://github.com/appcelerator/titanium_mobile/pull/1373\r\n\r\nIn addition to the changes to TiHost.m and KrollBridge.mm, the following steps need to be taken to include the example CommonJS compiled module in core for iOS:\r\n\r\n1. Create a module named \"test\" with ID \"test\". All JavaScript must be in assets/test.js.\r\n2. Compile it and unzip to a temporary directory.\r\n3. Copy libtest.a to iphone/lib/libtest.a in Titanium Mobile.\r\n4. Add libtest.a to titanium.xcodeproj.\r\n5. In site_scons/package.py, duplicate and update line 246 to copy libtest.a to the SDK distribution.\r\n6. In support/iphone/builder.py, duplicate and update lines 1013-1014 to add a check to copy libtest.a if it does not already exist.\r\n7. In support/iphone/iphone.py, duplicate and update line 116 to get a reference to libtest.a's path.\r\n8. In support/iphone/iphone.py, duplicate and update line 122 to copy libcloud.a to generated projects.", "updateAuthor": { "name": "dtoth", "key": "dtoth", "displayName": "Dawson Toth", "active": true, "timeZone": "America/New_York" }, "created": "2012-02-08T09:12:08.000+0000", "updated": "2012-02-08T09:12:08.000+0000" }, { "id": "413252", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as fixed.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-16T22:02:54.000+0000", "updated": "2017-03-16T22:02:54.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }