Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14721] LiveView: App.js Lexical Scope local vars not globally available

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-08-07T01:40:50.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 16, 2013 Sprint 16 Tooling, Release 3.1.3, Release 3.2.0
ComponentsLiveView
Labelsqe-closed-3.2.0
ReporterChristian Sullivan
AssigneeChristian Sullivan
Created2013-07-31T21:09:21.000+0000
Updated2014-01-02T09:23:35.000+0000

Description

Variable defined in the app.js are not globally available. This is due to the project's app.js being executed outside of first loaded app.js context. TEST Normal 1) Create app with code snippets below 2) Build app Result: console will output 'Lex Scope Var' TEST Liveview 1) Create app with code snippets below 2) Build app with --liveview flag Expected Result: console will output 'Lex Scope Var' Actual Result: error due to lexvar not being defined Example Code
//app.js
var lexvar = 'Lex Scope Var';
var require('test');
//test.js
console.log(lexvar);

Comments

  1. Ingo Muschenetz 2013-08-01

    From Tony: To get around this issue, developers would need to explicitly re-require Alloy:
       var Alloy = require('alloy');
       
    And there's also underscore(_) and Backbone to worry about as well. Those require statements are part of every Alloy-generated controller, but anything in the developer's "lib" or "assets" folder I have no control over. In those situations developers are relying on the global presence of Alloy. And they do it a lot, as it was one of the most asked Q&A questions until Android made them global as well.
  2. Christian Sullivan 2013-08-05

    Added support for injecting local lexical scope vars in user's app.js in to the project's 'Global' context https://github.com/euforic/liveview/tree/bug/TIMOB-14721
  3. Michael Xia 2013-08-06

    [~csullivan] I'm getting a 404 when clicking on the link. Is the branch pushed to remote yet?
  4. Christian Sullivan 2013-08-06

    It's already part of master.
  5. Michael Xia 2013-08-06

    Re-opening as running Field Service app is showing the following error:
       [LiveView] Client connected
       [ 'Alloy', '_', 'Backbone', 'e', 'APP' ]
       [INFO] :   [LiveView] Error Evaluating app.js @ Line: 1
       [ERROR] :  ReferenceError: Can't find variable: e
       [ERROR] :  File: app.js
       [ERROR] :  Line: 1
       [ERROR] :  SourceId: 341460448
       [ERROR] :  Backtrace:
       [ERROR] :   #0 () at file://localhost/Users/mxia/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/27D57553-41DC-4C4C-8DAB-11A2F6869224/Ti.FieldService.app/app.js:628
       [ERROR] :  #1 () at file://localhost/Users/mxia/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/27D57553-41DC-4C4C-8DAB-11A2F6869224/Ti.FieldService.app/app.js:493
       [ERROR] :  #2 () at file://localhost/Users/mxia/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/27D57553-41DC-4C4C-8DAB-11A2F6869224/Ti.FieldService.app/app.js:460
       [ERROR] :  #3 () at file://localhost/Users/mxia/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/27D57553-41DC-4C4C-8DAB-11A2F6869224/Ti.FieldService.app/app.js:392
       [ERROR] :  #4 () at file://localhost/Users/mxia/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/27D57553-41DC-4C4C-8DAB-11A2F6869224/Ti.FieldService.app/app.js:663
       
  6. Christian Sullivan 2013-08-07

    fixed in [master] https://github.com/appcelerator/liveview/commit/d0901508657d4c11479cddb4a050574069f99076 Released in version 0.1.30 https://github.com/appcelerator/liveview/releases/tag/0.1.30
  7. Priya Agarwal 2014-01-02

    Verified with test Environment: Appc-Studio: 3.2.0.201312191455 Sdk:3.2.0.GA acs:1.0.11 alloy:1.3.0 npm:1.3.2 titanium:3.2.0 titanium-code-processor:1.1.0 Osx: Maverick 10.9 Xcode: xCode 5.0.2 Device: Google Nexus7(v4.4.2),Iphone Simulator(v7.0.3) Getting the required console logs with both liveView enabled and disabled. Hence alosing as fixed and Verified.

JSON Source