src/virtual-scrolling-tree/VirtualScrollingTree.js
function buildRequest(scrollPos, viewport) {
    // Variables
    let queries = [];
    let requestedTotal = 0;
    let expanded = _(this).expansions;

    sortExpansions.call(this);
    calculateExpansions.call(this);

    // One-dimensional collision detection. 
    // It checks to see if start/end are both either before 
    // the viewport, and after. If it's not before or after, it's colliding.
    let inViewPort = function(v1, v2, e1, e2) {
        return !((e1 < v1 && e2 < v1) || (e1 > v2 && e2 > v2));
    };

    let calculateExpansionQueries = function(expansions, parentQuery) {

        expansions.forEach((e) => {

            if (inViewPort(scrollPos, scrollPos + viewport, e._start, e._end)) {
                
                // We want to find out how many items for this expansion are 
                // visible in the view port. To do this we find the first item that's
                // visible, the last item that's visible, subtract them and cap it to the viewport size.
                let start = Math.max(scrollPos, e._start);
                let end = Math.min(scrollPos + viewport - 1, e._end);
                let visible = Math.max(0, Math.min(end - start + 1, viewport));

                if (parentQuery) {
                    // If there are nested children visible, we need to subtract 
                    // this from the parent. Note that visible also includes any expanded
                    // children nested further because we're using the _start and _end 
                    // values we've already calculated.
                    parentQuery.limit -= visible;

                    if (scrollPos > e._start) {
                        let notVisible = (e._end - e._start + 1) - visible;
                        if (notVisible > 0) {
                            parentQuery.offset -= notVisible;
                        }
                    }
                }

                // This query object is what's given to the end user.
                // The parent represents who we want the children of.
                // The offset is based on how much we've scrolled past the beginning.
                // The limit is total items that are visible in the viewport.
                let query = {
                    parent: e.id,
                    offset: scrollPos > e._start? scrollPos - e._start : 0,
                    limit: Math.min(visible, viewport)
                };

                queries.push(query);
                calculateExpansionQueries(e.expansions, query);
            } else if (scrollPos > e._end && parentQuery) {
                // If we've completely scrolled past this object, just substract all of its expanded children from the parent offset.
                parentQuery.offset -= (e._end - e._start + 1);
            }
            
        });
    };
    
    calculateExpansionQueries(_(this).expansions);
    return queries;

}
function buildRequest(scrollPos, viewport) {
    // Variables
    let queries = [];
    let requestedTotal = 0;
    let expanded = _(this).expansions;

    sortExpansions.call(this);
    calculateExpansions.call(this);

    // One-dimensional collision detection. 
    // It checks to see if start/end are both either before 
    // the viewport, and after. If it's not before or after, it's colliding.
    let inViewPort = function(v1, v2, e1, e2) {
        return !((e1 < v1 && e2 < v1) || (e1 > v2 && e2 > v2));
    };

    let calculateExpansionQueries = function(expansions, parentQuery) {

        expansions.forEach((e) => {

            if (inViewPort(scrollPos, scrollPos + viewport, e._start, e._end)) {
                
                // We want to find out how many items for this expansion are 
                // visible in the view port. To do this we find the first item that's
                // visible, the last item that's visible, subtract them and cap it to the viewport size.
                let start = Math.max(scrollPos, e._start);
                let end = Math.min(scrollPos + viewport - 1, e._end);
                let visible = Math.max(0, Math.min(end - start + 1, viewport));

                if (parentQuery) {
                    // If there are nested children visible, we need to subtract 
                    // this from the parent. Note that visible also includes any expanded
                    // children nested further because we're using the _start and _end 
                    // values we've already calculated.
                    parentQuery.limit -= visible;

                    if (scrollPos > e._start) {
                        let notVisible = (e._end - e._start + 1) - visible;
                        if (notVisible > 0) {
                            parentQuery.offset -= notVisible;
                        }
                    }
                }

                // This query object is what's given to the end user.
                // The parent represents who we want the children of.
                // The offset is based on how much we've scrolled past the beginning.
                // The limit is total items that are visible in the viewport.
                let query = {
                    parent: e.id,
                    offset: scrollPos > e._start? scrollPos - e._start : 0,
                    limit: Math.min(visible, viewport)
                };

                queries.push(query);
                calculateExpansionQueries(e.expansions, query);
            } else if (scrollPos > e._end && parentQuery) {
                // If we've completely scrolled past this object, just substract all of its expanded children from the parent offset.
                parentQuery.offset -= (e._end - e._start + 1);
            }
            
        });
    };
    
    calculateExpansionQueries(_(this).expansions);
    return queries;

}
function buildRequest ( scrollPos , viewport ) { // Variables let queries = [ ] ; let requestedTotal = 0 ; let expanded = _ ( this ) . expansions ; sortExpansions . call ( this ) ; calculateExpansions . call ( this ) ; // One-dimensional collision detection.  // It checks to see if start/end are both either before  // the viewport, and after. If it's not before or after, it's colliding. let inViewPort = function ( v1 , v2 , e1 , e2 ) { return ! ( ( e1 < v1 && e2 < v1 ) || ( e1 > v2 && e2 > v2 ) ) ; } ; let calculateExpansionQueries = function ( expansions , parentQuery ) { expansions . forEach ( ( e ) => { if ( inViewPort ( scrollPos , scrollPos + viewport , e . _start , e . _end ) ) { // We want to find out how many items for this expansion are  // visible in the view port. To do this we find the first item that's // visible, the last item that's visible, subtract them and cap it to the viewport size. let start = Math . max ( scrollPos , e . _start ) ; let end = Math . min ( scrollPos + viewport - 1 , e . _end ) ; let visible = Math . max ( 0 , Math . min ( end - start + 1 , viewport ) ) ; if ( parentQuery ) { // If there are nested children visible, we need to subtract  // this from the parent. Note that visible also includes any expanded // children nested further because we're using the _start and _end  // values we've already calculated. parentQuery . limit -= visible ; if ( scrollPos > e . _start ) { let notVisible = ( e . _end - e . _start + 1 ) - visible ; if ( notVisible > 0 ) { parentQuery . offset -= notVisible ; } } } // This query object is what's given to the end user. // The parent represents who we want the children of. // The offset is based on how much we've scrolled past the beginning. // The limit is total items that are visible in the viewport. let query = { parent : e . id , offset : scrollPos > e . _start ? scrollPos - e . _start : 0 , limit : Math . min ( visible , viewport ) } ; queries . push ( query ) ; calculateExpansionQueries ( e . expansions , query ) ; } else if ( scrollPos > e . _end && parentQuery ) { // If we've completely scrolled past this object, just substract all of its expanded children from the parent offset. parentQuery . offset -= ( e . _end - e . _start + 1 ) ; } } ) ; } ; calculateExpansionQueries ( _ ( this ) . expansions ) ; return queries ; }
Calculates what's in the viewport and generates a series
of queries for the developer to respond to.

@method buildRequest
@private
Calculates what s in the viewport and generates a series of queries for the developer to respond to .