rstacruz / nprogress

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

Nprogress with Backbone #58

Open narayanpai opened 10 years ago

narayanpai commented 10 years ago

I'm trying to display nprogress when the views are being rendered using backbone. The nprogress progesses smothely, but gets stuck at the end and never stops. How could i fix this. Below is the code snippet that im trying to do

    app.NProgress.start();

    this.collection.each( function( item ){
        this.renderPhotoSet( item );
        app.NProgress.inc();
    }, this );

    app.NProgress.done();
vishalsood commented 10 years ago

@narayanpai the .inc is being called inside the callback function. So the "done" is getting called first and then callback fires and then inc gets called. Not sure what NProgress does in that case.

pavlos-io commented 9 years ago

Put "app.NProgress.inc();" before the loop, it's going to increment anyways. Use Undescore's _.each(), which is synchronous, to loop through the collection and then "app.NProgress.done();" will fire after the loop.