Skip to content

Instantly share code, notes, and snippets.

@Javiani
Created August 31, 2020 21:23
Show Gist options
  • Save Javiani/0e3585228ad22f09f6fa35ea4cf37f62 to your computer and use it in GitHub Desktop.
Save Javiani/0e3585228ad22f09f6fa35ea4cf37f62 to your computer and use it in GitHub Desktop.
export const request = async ( type ) => {
const endpoint = endpoints[ type ] || type
const results = await requestEndpoint([], { endpoint, offset: null })
return results
}
const requestEndpoint = async ( list = [], { endpoint, offset } ) => {
if ( list.length && !offset )
return list
const { data } = await http.get('', { params: { endpoint, offset } })
const config = { endpoint, offset: data.offset }
return requestEndpoint([ ...list, ...Records(data)], config )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment