Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1599] Some parts of initialization code are not executed in Alloy project

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionInvalid
Resolution Date2014-05-15T18:48:00.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterFix Please
AssigneeTony Lukasavage
Created2014-05-14T19:22:48.000+0000
Updated2016-03-08T07:38:04.000+0000

Description

alert('Hello 1');

(function (){
  alert('Hello 2');
})();

alert('Hello 3');

(function (){
  alert('Hello 4');
})();

alert('Hello 5');
In Classic project all the messages are shown in opposite order: 'Hello 5', 'Hello 4', 'Hello 3', 'Hello 2', 'Hello 1'. In Alloy project the same code shows the last message ('Hello 5') *only*.

Comments

  1. Fix Please 2014-05-15

    Below is one more test case. The same as before, the 'Classic' project shows all the messages but *in strange order*: 'Hello 5', 'Hello 4', 'Hello 3', 'Hello 2', 'Hello 1'. Alloy project shows the last message ('Hello 5') *only*. *Take a look, please.*
       (function() {
       
       alert('Hello 1');
       
       (function (){
         alert('Hello 2');
       })();
       
       alert('Hello 3');
       
       (function (){
         alert('Hello 4');
         alert('Hello 5');
       })();
       
       }());
       
  2. Fokke Zandbergen 2014-05-15

    Where do you have this code? In a controller, lib or alloy.js? And what does the compiled code looks like?
  3. Fix Please 2014-05-15

    {quote} Where do you have this code? In a controller, lib or alloy.js? {quote} I've just created a new test Alloy project from the scratch in order to re-check the issue once again.

    Case 1.

    *index.js* is empty. *alloy.js* is as follows:
       (function() {
       
       alert('Hello from alloy.js 1');
       
       (function (){
         alert('Hello from alloy.js 2');
       })();
       
       alert('Hello from alloy.js 3');
       
       (function (){
         alert('Hello from alloy.js 4');
         alert('Hello from alloy.js 5');
       })();
       
       }());
       

    The result:

    Hello from alloy.js 5 Hello from alloy.js 4 Hello from alloy.js 3 Hello from alloy.js 2 Hello from alloy.js 1
  4. Fix Please 2014-05-15

    Case 2.

    *alloy.js* is empty. *index.js* is as follows:
       (function() {
       
       alert('Hello from index.js 1');
       
       (function (){
         alert('Hello from index.js 2');
       })();
       
       alert('Hello from index.js 3');
       
       (function (){
         alert('Hello from index.js 4');
         alert('Hello from index.js 5');
       })();
       
       }());

    The result:

    Hello from index.js 5 Hello from index.js 4 Hello from index.js 3 Hello from index.js 2 Hello from index.js 1
  5. Fix Please 2014-05-15

    Case 3.

    *alloy.js* is empty. *index.js* is as follows (note, $.index.open() is added this time):
       (function() {
       
       alert('Hello from index.js 1');
       
       (function (){
         alert('Hello from index.js 2');
       })();
       
       alert('Hello from index.js 3');
       
       (function (){
         alert('Hello from index.js 4');
         alert('Hello from index.js 5');
       })();
       
       $.index.open();
       
       }());

    The result:

    Hello from index.js 5
  6. Fix Please 2014-05-15

    Case 4.

    *alloy.js* is as follows:
       (function() {
       
       alert('Hello from alloy.js 1');
       
       (function (){
         alert('Hello from alloy.js 2');
       })();
       
       alert('Hello from alloy.js 3');
       
       (function (){
         alert('Hello from alloy.js 4');
         alert('Hello from alloy.js 5');
       })();
       
       }());
       
    *index.js* is as follows:
       (function() {
       
       alert('Hello from index.js 1');
       
       (function (){
         alert('Hello from index.js 2');
       })();
       
       alert('Hello from index.js 3');
       
       (function (){
         alert('Hello from index.js 4');
         alert('Hello from index.js 5');
       })();
       
       $.index.open();
       
       }());

    The result:

    Hello from index.js 5
  7. Tony Lukasavage 2014-05-15

    The comparison here was poorly defined. The behavior between classic titanium and alloy is the same. Notice in your example everything works as expected until you add $.index.open(). If you create an equivalent classic titanium example, which augments your test case in the following way:
       var win = Ti.UI.createWindow();
       
       alert('Hello 1');
        
       (function (){
         alert('Hello 2');
       })();
        
       alert('Hello 3');
        
       (function (){
         alert('Hello 4');
       })();
        
       alert('Hello 5');
       
       win.open();
       
    The classic example behaves in the exact same way as alloy, showing only the last alert of alert('Hello 5'). This is behavior in Android that kills the pending alerts because a new activity is being opened when you open the main windows, which is win in the classic case, $.index in the alloy case. There is no disparity between alloy and titanium.
  8. Tony Lukasavage 2014-05-15

    Additional note: if it is important to you that you be able to queue large amounts of alert() calls even when a new Android activity is opened, you could request that this be reopened and moved to the TIMOB project, as it has nothing to do with Alloy. TBH though, I would imagine this might not get much love since it is an extremely impractical use case. Entirely up to you whether to pursue though, if you can make a case for it.
  9. Fix Please 2014-05-16

    {quote} you could request that this be reopened and moved to the TIMOB project {quote} No, thanks.

JSON Source