{ "id": "131918", "key": "AC-834", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "5", "description": "All attempts at reproducing this issue failed, or not enough information was available to reproduce the issue. Reading the code produces no clues as to why this behavior would occur. If more information appears later, please reopen the issue.", "name": "Cannot Reproduce" }, "resolutiondate": "2014-09-01T06:51:31.000+0000", "created": "2014-06-18T17:23:16.000+0000", "labels": [ "Alloy", "TCSupport" ], "versions": [], "issuelinks": [], "assignee": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "updated": "2016-03-08T07:37:07.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": "14544", "name": "Alloy", "description": "Please enter tickets related to the Alloy here." } ], "description": "When developing an Alloy Widget, the `Widget` scope is not available in CommonJS modules used within the widget. It seems like `Widget` should be available much like `Alloy` is available throughout all project JS resources. \r\n\r\nWhen defining models and collections on the Widget level, it makes it difficult to access them from CommonJS assets within a widget. I understand the `Widget` context can be passed into a module, however, this becomes tedious when dealing with a large project with many modules. \r\n\r\nThe `Widget` context be globally available on the widget level, no matter if it is a /controller/.js file or a /lib/.js file.", "attachment": [], "flagged": false, "summary": "`Widget` Scope Not Available in CommonJS Modules", "creator": { "name": "allenhartwig", "key": "allenhartwig", "displayName": "Allen Hartwig", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "allenhartwig", "key": "allenhartwig", "displayName": "Allen Hartwig", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Alloy 1.3.1 TiSDK 3.2.3GA", "comment": { "comments": [ { "id": "309645", "author": { "name": "allenhartwig", "key": "allenhartwig", "displayName": "Allen Hartwig", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Additionally the WPATH() method does not seem to be accessible outside of the controller directory, including the models directory. If a /models/myModel.js would like to use a common utils.js CommonJS in the /lib/ folder of my widget, there is no way to easily require it; relative paths don't even work, eg: require('../lib/utils.js').", "updateAuthor": { "name": "allenhartwig", "key": "allenhartwig", "displayName": "Allen Hartwig", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-06-18T18:00:23.000+0000", "updated": "2014-06-18T18:00:23.000+0000" }, { "id": "317834", "author": { "name": "morahman", "key": "morahman", "displayName": "Motiur Rahman", "active": true, "timeZone": "Asia/Dhaka" }, "body": "Hello,\r\n\r\nWe have tested this issue for a simple test case. And we can pass value from widget to commonJS scope easily. \r\n\r\nh3.Testing Environment: \r\nTitanium SDK: 3.3.0.GA,\r\nTitanium CLI: 3.3.0,\r\nAndroid SDK: 4.4.2,4.2.2,\r\nIOS Simulator: 7.1,\r\nOS X Version: 10.9.3,\r\nAppcelerator Studio: 3.3.0\r\n\r\nh3.Steps to Test:\r\n1. Create a Alloy project.\r\n2. Create a widget named test .\r\n2. Paste this code in index.js , index.xml file and widget.js ,widget.xml file\r\n3. Run this code with the testing environment.\r\n\r\nh3.Test Code\r\n{code:title=index.xml}\r\n\r\n\t\r\n\t\t\r\n\t\t\r\n\t\r\n\r\n{code}\r\n\r\n{code:title=index.js}\r\nfunction doClick() {\r\n\talert($.testWidget.testValue());\r\n\r\n}\r\n\r\n$.index.open();\r\n\r\n{code}\r\n\r\n{code:title=widget.xml}\r\n\r\n\r\n\t\r\n\t\t\r\n\t\t\r\n\t\r\n\r\n{code}\r\n\r\n{code:title=widget.js}\r\nexports.testValue = function() {\r\n\r\n\treturn $.text.value;\r\n\r\n};\r\n\r\n\r\n{code}\r\n\r\nThanks.\r\n", "updateAuthor": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "created": "2014-08-10T06:36:33.000+0000", "updated": "2014-09-01T06:50:44.000+0000" }, { "id": "321198", "author": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "body": "Please take a look into the provided testcase. If you can still reproduce, please provide a testcase that will show the issue. ", "updateAuthor": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "created": "2014-09-01T06:51:31.000+0000", "updated": "2014-09-01T06:51:31.000+0000" }, { "id": "335922", "author": { "name": "reymundolopez", "key": "reymundolopez", "displayName": "Reymundo López", "active": true, "timeZone": "America/Mexico_City" }, "body": "The example provided is wrong, it does not make use of any CommonJS modules inside of the /lib folder inside of the widget, here is a more apropiate example:\r\n\r\n* Create a blank Alloy App\r\n* Create a widget called test\r\n* Add the two CommonJS modules listed bellow\r\n* Try to run the app\r\n\r\n{code:title=index.js|borderStyle=solid}\r\nfunction doClick(e) {\r\n alert($.label.text);\r\n}\r\n\r\n$.index.open();\r\n{code}\r\n\r\n{code:title=index.xml|borderStyle=solid}\r\n\r\n\t\r\n\t\t\r\n\t\t\r\n\t\r\n\r\n{code}\r\n\r\n{code:title=widgets/test/widget.xml|borderStyle=solid}\r\n\r\n\t\r\n\r\n{code}\r\n\r\n{code:title=widgets/test/widget.js|borderStyle=solid}\r\nvar simple = require(WPATH('simple'));\r\n\r\nfunction startWorking(){\r\n\tsimple.getSolutionToWork();\r\n}\r\n{code}\r\n\r\n{code:title=widgets/test/lib/simple.js|borderStyle=solid}\r\nvar solution = require(WPATH('solution'));\r\nmodule.exports = (function(){\r\n\tvar getSolutionToWork = function(){\r\n\t\tsolution.work();\r\n\t};\r\n\r\n\treturn { \r\n\t\tgetSolutionToWork : getSolutionToWork\r\n\t};\r\n})();\r\n{code}\r\n\r\n{code:title=widgets/test/lib/solution.js|borderStyle=solid}\r\nmodule.exports = (function(){\r\n\tvar work = function(){\r\n\t\tTi.API.log(\"I'm working\");\r\n\t};\r\n\r\n\treturn { \r\n\t\twork : work\r\n\t};\r\n})();\r\n{code}\r\n\r\nExpected result will be to get a message in the console.\r\n\r\nActual result is {{Can't find variable: WPATH}}\r\n\r\nAnd the same goes for {{Widget.generateController()}} or the {{Widget}} variable alone inside of any CommonJS file located inside of the {{lib}} folder of any widget.", "updateAuthor": { "name": "reymundolopez", "key": "reymundolopez", "displayName": "Reymundo López", "active": true, "timeZone": "America/Mexico_City" }, "created": "2014-12-11T00:41:47.000+0000", "updated": "2014-12-11T00:41:47.000+0000" }, { "id": "343247", "author": { "name": "vdegroote", "key": "vdegroote", "displayName": "Vincent Degroote", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hello,\r\n\r\nI have the same problem, my fix was to inject from the controller the Widget namespace or the WPATH helper into the lib. It becomes really annoying when you want to require a lib into another. Could we reopen this issue?", "updateAuthor": { "name": "vdegroote", "key": "vdegroote", "displayName": "Vincent Degroote", "active": true, "timeZone": "Europe/Berlin" }, "created": "2015-02-13T10:20:56.000+0000", "updated": "2015-02-13T10:20:56.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }