rstacruz / nprogress

For slim progress bars like on YouTube, Medium, etc
http://ricostacruz.com/nprogress
MIT License
26.09k stars 1.81k forks source link

about `queue` function in `NProgress.set` function #172

Closed yyman001 closed 7 years ago

yyman001 commented 7 years ago

queue callback will is undefind,

var queue = (function() {
    var pending = [];

    function next() {
      var fn = pending.shift(); //run after will all undeind
      if (fn) {
        fn(next);
      }
    }

    return function(fn) {
      pending.push(fn);
      if (pending.length == 1) next();
    };
  })();

so the code edit after,

queue(function(next) {
      // Set positionUsing if it hasn't already been set
      if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS();

      // Add transition
      css(bar, barPositionCSS(n, speed, ease));

      if (n === 1) {
        // Fade out
        css(progress, {
          transition: 'none',
          opacity: 1
        });
        progress.offsetWidth; /* Repaint */

        setTimeout(function() {
          css(progress, {
            transition: 'all ' + speed + 'ms linear',
            opacity: 0
          });
          setTimeout(function() {
            NProgress.remove();
            //next();
          }, speed);
        }, speed);
      }

      // else {
     //   setTimeout(next, speed);  // Significance ?
    //  }
});

del after will run no problem,no error. But,i don't know why write this. for a test demo:http://yyman001.github.io/nprogress.js/index.html i want to know it why write this, thanks.

baohangxing commented 3 years ago

I also want know why @yyman001