function fetchAllPages(breedingAPIEndpoint, path, params) {
  let url = joinPaths(breedingAPIEndpoint, path)
  let deferred = $.Deferred()

  // override default query parameters with user given parameters
  let page = 0
  let req = $.get(url, {...params, page})

  // Request successfull
  req.done(function(response) {
    // results of the first page
    let firstPageData
    try {
      firstPageData = getBrapiData(response)
    } catch(error) {
      return deferred.reject(error)
    }
    let totalPages = response.metadata.pagination.totalPages

    // Prepare Ajax request for all other pages (if any)
    let requests = []
    while (page < totalPages - 1) {
      page++
      requests.push($.get(url, {...params, page}))
    }

    if (requests.length >= 1) {
      // Executing all page requests asynchronously
      whenAll(requests).done(function(responses) {
        // Aggregate results of all pages (except the first)
        let otherPagesData = $.map(responses, function(response) {
          try {
            return getBrapiData(response[0])
          } catch(error) {
            return deferred.reject(error)
          }
        })

        // concat results and resolve the deferred
        deferred.resolve(firstPageData.concat(otherPagesData))
      })
    } else {
      // Only one page
      deferred.resolve(firstPageData)
    }
  })

  // Request failed
  req.fail(deferred.reject)

  // Return "deferred" value (aka. "future" value)
  return deferred
}
/**
 * Asynchronously fetch all pages of a Breeding API call
 */
Asynchronously fetch all pages of a Breeding API call
Asynchronously fetch all pages of a Breeding API call
function fetchAllPages(breedingAPIEndpoint, path, params) {
  let url = joinPaths(breedingAPIEndpoint, path)
  let deferred = $.Deferred()
  let page = 0
  let req = $.get(url, {...params, page})
  req.done(function(response) {
    let firstPageData
    try {
      firstPageData = getBrapiData(response)
    } catch(error) {
      return deferred.reject(error)
    }
    let totalPages = response.metadata.pagination.totalPages
    let requests = []
    while (page < totalPages - 1) {
      page++
      requests.push($.get(url, {...params, page}))
    }
    if (requests.length >= 1) {
      whenAll(requests).done(function(responses) {
        let otherPagesData = $.map(responses, function(response) {
          try {
            return getBrapiData(response[0])
          } catch(error) {
            return deferred.reject(error)
          }
        })
        deferred.resolve(firstPageData.concat(otherPagesData))
      })
    } else {
      deferred.resolve(firstPageData)
    }
  })
  req.fail(deferred.reject)
  return deferred
}
function fetchAllPages ( breedingAPIEndpoint , path , params ) { let url = joinPaths ( breedingAPIEndpoint , path ) let deferred = $ . Deferred ( ) let page = 0 let req = $ . get ( url , { ... params , page } ) req . done ( function ( response ) { let firstPageData try { firstPageData = getBrapiData ( response ) } catch ( error ) { return deferred . reject ( error ) } let totalPages = response . metadata . pagination . totalPages let requests = [ ] while ( page < totalPages - 1 ) { page ++ requests . push ( $ . get ( url , { ... params , page } ) ) } if ( requests . length >= 1 ) { whenAll ( requests ) . done ( function ( responses ) { let otherPagesData = $ . map ( responses , function ( response ) { try { return getBrapiData ( response [ 0 ] ) } catch ( error ) { return deferred . reject ( error ) } } ) deferred . resolve ( firstPageData . concat ( otherPagesData ) ) } ) } else { deferred . resolve ( firstPageData ) } } ) req . fail ( deferred . reject ) return deferred }
Asynchronously fetch all pages of a Breeding API call
Asynchronously fetch all pages of a Breeding API call
// override default query parameters with user given parameters // Request successfull // results of the first page // Prepare Ajax request for all other pages (if any) // Executing all page requests asynchronously // Aggregate results of all pages (except the first) // concat results and resolve the deferred // Only one page // Request failed // Return "deferred" value (aka. "future" value)