Skip to content

Commit

Permalink
Tweak SDK request logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Sep 17, 2019
1 parent 8c482b0 commit 2e65010
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export function getSDK (url, sdkGlobal, sdkReady = null, isLoaded = () => true,
// If we are already loading the SDK, add the resolve and reject
// functions to the existing array of requests
if (requests[url]) {
requests[url].push({ resolve: resolve, reject: reject })
requests[url].push({ resolve, reject })
return
}
requests[url] = [{ resolve: resolve, reject: reject }]
requests[url] = [{ resolve, reject }]
const onLoaded = sdk => {
// When loaded, resolve all pending request promises
requests[url].forEach(request => request.resolve(sdk))
Expand All @@ -85,10 +85,10 @@ export function getSDK (url, sdkGlobal, sdkReady = null, isLoaded = () => true,
}
fetchScript(url, err => {
if (err) {
// Loading the SDK failed, reject all requests and delete
// the array of requests for this SDK
// Loading the SDK failedreject all requests and
// reset the array of requests for this SDK
requests[url].forEach(request => request.reject(err))
delete requests[url]
requests[url] = []
} else if (!sdkReady) {
onLoaded(window[sdkGlobal])
}
Expand Down

0 comments on commit 2e65010

Please sign in to comment.