[AC-834] `Widget` Scope Not Available in CommonJS Modules
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2014-09-01T06:51:31.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy |
Labels | Alloy, TCSupport |
Reporter | Allen Hartwig |
Assignee | Mauro Parra-Miranda |
Created | 2014-06-18T17:23:16.000+0000 |
Updated | 2016-03-08T07:37:07.000+0000 |
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.
When 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.
The Widget
context be globally available on the widget level, no matter if it is a /controller/.js file or a /lib/.js file.
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').
Hello, We have tested this issue for a simple test case. And we can pass value from widget to commonJS scope easily.
Testing Environment:
Titanium SDK: 3.3.0.GA, Titanium CLI: 3.3.0, Android SDK: 4.4.2,4.2.2, IOS Simulator: 7.1, OS X Version: 10.9.3, Appcelerator Studio: 3.3.0Steps to Test:
1. Create a Alloy project. 2. Create a widget named test . 2. Paste this code in index.js , index.xml file and widget.js ,widget.xml file 3. Run this code with the testing environment.Test Code
Thanks.
Please take a look into the provided testcase. If you can still reproduce, please provide a testcase that will show the issue.
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: * Create a blank Alloy App * Create a widget called test * Add the two CommonJS modules listed bellow * Try to run the app
Expected result will be to get a message in the console. Actual result is
Can't find variable: WPATH
And the same goes forWidget.generateController()
or theWidget
variable alone inside of any CommonJS file located inside of thelib
folder of any widget.Hello, I 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?