lib/pages.js
function(callback){
    var self = this;

    // if we have no pages just fire callback
    if(self.pageCollection.length === 0){
      callback(self);
    }

    // this is called once a page is fully parsed
    whenPageIsFetched = function(){
      self.completed ++;
      if(self.completed === self.pageCollection.length){
        callback(self);
      } else {
        findUnfetchedPages();
      }  
    }

    findUnfetchedPages = function(){ 
      _.each(self.pageCollection, function (page) {
        if (page.status === "unfetched") {
          page.fetch(whenPageIsFetched);
        }
      });
    },

    findUnfetchedPages();
  }
function(callback){
    var self = this;

    // if we have no pages just fire callback
    if(self.pageCollection.length === 0){
      callback(self);
    }

    // this is called once a page is fully parsed
    whenPageIsFetched = function(){
      self.completed ++;
      if(self.completed === self.pageCollection.length){
        callback(self);
      } else {
        findUnfetchedPages();
      }  
    }

    findUnfetchedPages = function(){ 
      _.each(self.pageCollection, function (page) {
        if (page.status === "unfetched") {
          page.fetch(whenPageIsFetched);
        }
      });
    },

    findUnfetchedPages();
  }
function ( callback ) { var self = this ; // if we have no pages just fire callback if ( self . pageCollection . length === 0 ) { callback ( self ) ; } // this is called once a page is fully parsed whenPageIsFetched = function ( ) { self . completed ++ ; if ( self . completed === self . pageCollection . length ) { callback ( self ) ; } else { findUnfetchedPages ( ) ; } } findUnfetchedPages = function ( ) { _ . each ( self . pageCollection , function ( page ) { if ( page . status === "unfetched" ) { page . fetch ( whenPageIsFetched ) ; } } ) ; } , findUnfetchedPages ( ) ; }
fetch all the pages
fetch all the pages