Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2864] Android: CommonJS required file not able to access global variables

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2011-12-19T16:55:58.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labels1.8.0.1, android, commonJS
ReporterTrevor Ward
AssigneePaul Dowsett
Created2011-12-04T08:57:55.000+0000
Updated2016-03-08T07:47:48.000+0000

Description

I have coded an app which includes specific control files in the app.js file. These use namesakes and anonymous functions. To avoid loading all files at runtime I then require using the commonJS method the files I need at the time a window is loaded. The issue is that the namespace variables defined in the app.js included file are not found, it crashes with the namespace not being found. I have created a test case of this. Which works on IOS and Android using SDK 1.8.0. and the latest nightly build of 1.7.6 but not on previous versions of 1.7.6 There are 5 files but very little code in each one, I needed 5 as a minimum to show it working and failing. The path structure can be seen in the app.js file, I have also created a git repository with the info in. https://github.com/thewarpedcoder/AndroidTestCase Thanks T.

Attachments

FileDateSize
app.js2011-12-04T08:57:55.000+0000569
ATCNS-CTL.js2011-12-04T08:57:55.000+0000540
ATCNS-HELP-GlobalVariables.js2011-12-04T08:57:55.000+0000186
ATCNS-VIEW-MainScreen.js2011-12-04T08:57:55.000+0000568
ATCNS-VIEW-NextScreen.js2011-12-04T08:57:55.000+0000545

Comments

  1. Paul Dowsett 2011-12-04

    Hi Trevor Would you mind reading TIMOB-6033, especially the comments by Rick and Marshall. We need to be certain that the issue you describe is not already covered in that one, before moving it across. Also, please see the guidance at [JIRA Ticket Checklist](http://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) - for simple test cases, it's better to add code to the body of the ticket. Cheers
  2. Trevor Ward 2011-12-04

    Hi Paul. Not sure how I missed Marshalls comment. Obviously just skipped onto the next one. dyslexia again.. (well I am blaming it) OK my take on this. The 1.8.0 Sdk is potentially the one with the CommonJS bug in by allowing for global variables. 1.8.0.1 seems to have altered the implementation which is why my refactoring now does not work. I will have to look at this in greater detail in relation to this specific issue as Kevin has also used setters and getters for values. which is also a solution and would work really well in this scenario.. I will code a second test case where no Ti.includes are used at all, all that happens is namespaces are used to require the file into and then the current global variables are set using there own file, which is private and each has a setter and getter. The issue I think is that I did not fully understand that even namespaces variables are being considered global. Which in fact they are. My real issue now is that I use this method of populating a namespace with values To define static values like colours or fonts and sizes, and text so I only have one file which requires changing to change static values but these are also not being allowed going forward. I am not sure which SDK now has this bug in. The TIMB-6033 Jira ticket is similar to this one, but is also different in that it specifically covers global variables being set and defined in required modules. I set them in the app.js by including the file which they are defined in and they are not then available, throughout the app as I would have hoped. Is this because I am implementing the static variables incorrectly. This test case shows an example of a static value to be used throughout the app. I hope I have explained this ok, and am very happy if this is not a bug and 1.8.0 having the issue, but how would I then define a global static variable. Point well made and taken on setting and getting global values. Also I have not raised many Jira tickets so please continue to point out the correct way to raise them hopefully I never get competent in them as this would mean I was raising way to many. Thanks T.
  3. Paul Dowsett 2011-12-19

    Thanks for all the cooperation you have given with CommonJS, Trevor. As you have agreed with Kevin Whinnery, this behavior is by design, in line with the CommonJS spec. If you still believe it to be incorrect, please reopen. Cheers

JSON Source