简体   繁体   中英

App stop working (with no errors in console) after “grunt build”

I am building an AngularJS app using yeoman + bower + grunt. The app is working perfectly till I build with grunt, although no error is returned.

In my app I am basically asking the user to pick a value from 1 to 7 in a select and according to the pick the app generates a series of random numbers (and executes more actions thereafter).

Apparently the function to generate random numbers is working in my test environment but after building and deploying the dist, I only get a series of 0.

This is the function:

$scope.numbers = function getNumbers (pick) {
    var min = 0;
    var max = 0;
    var numbers = {
      '0': function () {
        min = 0;
        max = 0;
      },
      '1': function () {
        min = 1;
        max = 3;
      },
      '2': function () {
        min = 3;
        max = 5;
      },
      '3': function () {
        min = 5;
        max = 8;
      },
      '4': function () {
        min = 8;
        max = 13;
      },
      '5': function () {
        min = 13;
        max = 21;
      },
      '6': function () {
        min = 21;
        max = 34;
      },
      '7': function () {
        min = 34;
        max = 55;
      },
      'default': function () {
        min = 0;
        max = 0;
      }
    };

    (numbers[pick] || numbers['default'])();
    var arr = [];
    // Generate a sequence of as many random numbers within the given range as the number of iterations
    for (var i=0; i<$scope.iterations; i++) {
      arr.push(Math.floor(Math.random() * (max - min + 1)) + min);
    }
    return arr;
  };

which is then used to create a new field: efforts: $scope.numbers($scope.pick)

So for some reason after building with grunt the function is not recognizing the value chosen by the user and it's returning always the default (0).

I already excluded:

  1. problems with the switch (since settings the variable to a value different from 0 at the beginning of the function is still returning zeroes)
  2. pick not being properly registered (it is correctly saved in Firebase and it's never 0)

Any hint?

UPDATE: I extracted this part from the minified file:

b.numbers=function(a){var c=0,d=0,e={0:function(){c=0,d=0},1:function(){c=1,d=3},2:function(){c=3,d=5},3:function(){c=5,d=8},4:function(){c=8,d=13},5:function(){c=13,d=21},6:function(){c=21,d=34},7:function(){c=34,d=55},"default":function(){c=0,d=0}};(e[a]||e["default"])();for(var f=[],g=0;g<b.iterations;g++)f.push(Math.floor(Math.random()*(d-c+1))+c);return f}

Ok I figured it out myself looking at the minified version and running a few tests. The problem was actually with the single quotes being stripped off by the minifier.

So I removed the quotes myself and ensured that the pick is passed as integer:

(numbers[parseInt(pick, 10)] || numbers['default'])();

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM