lib/request/GetRequestV2.js
function(requestedPaths, optimizedPaths, callback) {
        var self = this;
        var oPaths = self._optimizedPaths;
        var rPaths = self._requestedPaths;
        var callbacks = self._callbacks;
        var idx = oPaths.length;

        // If its not sent, simply add it to the requested paths
        // and callbacks.
        oPaths[idx] = optimizedPaths;
        rPaths[idx] = requestedPaths;
        callbacks[idx] = callback;
        ++self._count;

        // If it has not been scheduled, then schedule the action
        if (!self.scheduled) {
            self.scheduled = true;

            var flushedDisposable;
            var scheduleDisposable = self._scheduler.schedule(function() {
                flushedDisposable = flushGetRequest(self, oPaths, function(err, data) {
                    var i, fn, len;
                    var model = self.requestQueue.model;
                    self.requestQueue.removeRequest(self);
                    self._disposed = true;

                    if (model._treatDataSourceErrorsAsJSONGraphErrors ? err instanceof InvalidSourceError : !!err) {
                        for (i = 0, len = callbacks.length; i < len; ++i) {
                            fn = callbacks[i];
                            if (fn) {
                                fn(err);
                            }
                        }
                        return;
                    }

                    // If there is at least one callback remaining, then
                    // callback the callbacks.
                    if (self._count) {
                        // currentVersion will get added to each inserted
                        // node as node.$_version inside of self._merge.
                        //
                        // atom values just downloaded with $expires: 0
                        // (now-expired) will get assigned $_version equal
                        // to currentVersion, and checkCacheAndReport will
                        // later consider those nodes to not have expired
                        // for the duration of current event loop tick
                        //
                        // we unset currentCacheVersion after all callbacks
                        // have been called, to ensure that only these
                        // particular callbacks and any synchronous model.get
                        // callbacks inside of these, get the now-expired
                        // values
                        var currentVersion = incrementVersion.getCurrentVersion();
                        currentCacheVersion.setVersion(currentVersion);
                        var mergeContext = { hasInvalidatedResult: false };

                        var pathsErr = model._useServerPaths && data && data.paths === undefined ?
                            new Error("Server responses must include a 'paths' field when Model._useServerPaths === true") : undefined;

                        if (!pathsErr) {
                            self._merge(rPaths, err, data, mergeContext);
                        }

                        // Call the callbacks.  The first one inserts all
                        // the data so that the rest do not have consider
                        // if their data is present or not.
                        for (i = 0, len = callbacks.length; i < len; ++i) {
                            fn = callbacks[i];
                            if (fn) {
                                fn(pathsErr || err, data, mergeContext.hasInvalidatedResult);
                            }
                        }
                        currentCacheVersion.setVersion(null);
                    }
                });
                self._disposable = flushedDisposable;
            });

            // If the scheduler is sync then `flushedDisposable` will be
            // defined, and we want to use it, because that's what aborts an
            // in-flight XHR request, for example.
            // But if the scheduler is async, then `flushedDisposable` won't be
            // defined yet, and so we must use the scheduler's disposable until
            // `flushedDisposable` is defined. Since we want to still use
            // `flushedDisposable` once it is defined (to be able to abort in-
            // flight XHR requests), hence the reassignment of `_disposable`
            // above.
            self._disposable = flushedDisposable || scheduleDisposable;
        }

        // Disposes this batched request.  This does not mean that the
        // entire request has been disposed, but just the local one, if all
        // requests are disposed, then the outer disposable will be removed.
        return createDisposable(self, idx);
    }
function(requestedPaths, optimizedPaths, callback) {
        var self = this;
        var oPaths = self._optimizedPaths;
        var rPaths = self._requestedPaths;
        var callbacks = self._callbacks;
        var idx = oPaths.length;

        // If its not sent, simply add it to the requested paths
        // and callbacks.
        oPaths[idx] = optimizedPaths;
        rPaths[idx] = requestedPaths;
        callbacks[idx] = callback;
        ++self._count;

        // If it has not been scheduled, then schedule the action
        if (!self.scheduled) {
            self.scheduled = true;

            var flushedDisposable;
            var scheduleDisposable = self._scheduler.schedule(function() {
                flushedDisposable = flushGetRequest(self, oPaths, function(err, data) {
                    var i, fn, len;
                    var model = self.requestQueue.model;
                    self.requestQueue.removeRequest(self);
                    self._disposed = true;

                    if (model._treatDataSourceErrorsAsJSONGraphErrors ? err instanceof InvalidSourceError : !!err) {
                        for (i = 0, len = callbacks.length; i < len; ++i) {
                            fn = callbacks[i];
                            if (fn) {
                                fn(err);
                            }
                        }
                        return;
                    }

                    // If there is at least one callback remaining, then
                    // callback the callbacks.
                    if (self._count) {
                        // currentVersion will get added to each inserted
                        // node as node.$_version inside of self._merge.
                        //
                        // atom values just downloaded with $expires: 0
                        // (now-expired) will get assigned $_version equal
                        // to currentVersion, and checkCacheAndReport will
                        // later consider those nodes to not have expired
                        // for the duration of current event loop tick
                        //
                        // we unset currentCacheVersion after all callbacks
                        // have been called, to ensure that only these
                        // particular callbacks and any synchronous model.get
                        // callbacks inside of these, get the now-expired
                        // values
                        var currentVersion = incrementVersion.getCurrentVersion();
                        currentCacheVersion.setVersion(currentVersion);
                        var mergeContext = { hasInvalidatedResult: false };

                        var pathsErr = model._useServerPaths && data && data.paths === undefined ?
                            new Error("Server responses must include a 'paths' field when Model._useServerPaths === true") : undefined;

                        if (!pathsErr) {
                            self._merge(rPaths, err, data, mergeContext);
                        }

                        // Call the callbacks.  The first one inserts all
                        // the data so that the rest do not have consider
                        // if their data is present or not.
                        for (i = 0, len = callbacks.length; i < len; ++i) {
                            fn = callbacks[i];
                            if (fn) {
                                fn(pathsErr || err, data, mergeContext.hasInvalidatedResult);
                            }
                        }
                        currentCacheVersion.setVersion(null);
                    }
                });
                self._disposable = flushedDisposable;
            });

            // If the scheduler is sync then `flushedDisposable` will be
            // defined, and we want to use it, because that's what aborts an
            // in-flight XHR request, for example.
            // But if the scheduler is async, then `flushedDisposable` won't be
            // defined yet, and so we must use the scheduler's disposable until
            // `flushedDisposable` is defined. Since we want to still use
            // `flushedDisposable` once it is defined (to be able to abort in-
            // flight XHR requests), hence the reassignment of `_disposable`
            // above.
            self._disposable = flushedDisposable || scheduleDisposable;
        }

        // Disposes this batched request.  This does not mean that the
        // entire request has been disposed, but just the local one, if all
        // requests are disposed, then the outer disposable will be removed.
        return createDisposable(self, idx);
    }
function ( requestedPaths , optimizedPaths , callback ) { var self = this ; var oPaths = self . _optimizedPaths ; var rPaths = self . _requestedPaths ; var callbacks = self . _callbacks ; var idx = oPaths . length ; // If its not sent, simply add it to the requested paths // and callbacks. oPaths [ idx ] = optimizedPaths ; rPaths [ idx ] = requestedPaths ; callbacks [ idx ] = callback ; ++ self . _count ; // If it has not been scheduled, then schedule the action if ( ! self . scheduled ) { self . scheduled = true ; var flushedDisposable ; var scheduleDisposable = self . _scheduler . schedule ( function ( ) { flushedDisposable = flushGetRequest ( self , oPaths , function ( err , data ) { var i , fn , len ; var model = self . requestQueue . model ; self . requestQueue . removeRequest ( self ) ; self . _disposed = true ; if ( model . _treatDataSourceErrorsAsJSONGraphErrors ? err instanceof InvalidSourceError : ! ! err ) { for ( i = 0 , len = callbacks . length ; i < len ; ++ i ) { fn = callbacks [ i ] ; if ( fn ) { fn ( err ) ; } } return ; } // If there is at least one callback remaining, then // callback the callbacks. if ( self . _count ) { // currentVersion will get added to each inserted // node as node.$_version inside of self._merge. // // atom values just downloaded with $expires: 0 // (now-expired) will get assigned $_version equal // to currentVersion, and checkCacheAndReport will // later consider those nodes to not have expired // for the duration of current event loop tick // // we unset currentCacheVersion after all callbacks // have been called, to ensure that only these // particular callbacks and any synchronous model.get // callbacks inside of these, get the now-expired // values var currentVersion = incrementVersion . getCurrentVersion ( ) ; currentCacheVersion . setVersion ( currentVersion ) ; var mergeContext = { hasInvalidatedResult : false } ; var pathsErr = model . _useServerPaths && data && data . paths === undefined ? new Error ( "Server responses must include a 'paths' field when Model._useServerPaths === true" ) : undefined ; if ( ! pathsErr ) { self . _merge ( rPaths , err , data , mergeContext ) ; } // Call the callbacks.  The first one inserts all // the data so that the rest do not have consider // if their data is present or not. for ( i = 0 , len = callbacks . length ; i < len ; ++ i ) { fn = callbacks [ i ] ; if ( fn ) { fn ( pathsErr || err , data , mergeContext . hasInvalidatedResult ) ; } } currentCacheVersion . setVersion ( null ) ; } } ) ; self . _disposable = flushedDisposable ; } ) ; // If the scheduler is sync then `flushedDisposable` will be // defined, and we want to use it, because that's what aborts an // in-flight XHR request, for example. // But if the scheduler is async, then `flushedDisposable` won't be // defined yet, and so we must use the scheduler's disposable until // `flushedDisposable` is defined. Since we want to still use // `flushedDisposable` once it is defined (to be able to abort in- // flight XHR requests), hence the reassignment of `_disposable` // above. self . _disposable = flushedDisposable || scheduleDisposable ; } // Disposes this batched request.  This does not mean that the // entire request has been disposed, but just the local one, if all // requests are disposed, then the outer disposable will be removed. return createDisposable ( self , idx ) ; }
batches the paths that are passed in.  Once the request is complete,
all callbacks will be called and the request will be removed from
parent queue.
@param {Array} requestedPaths -
@param {Array} optimizedPaths -
@param {Function} callback -
batches the paths that are passed in . Once the request is complete all callbacks will be called and the request will be removed from parent queue .