generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
921b8c6
commit 0460829
Showing
8 changed files
with
47 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
let ready = false; | ||
let existingCall = null; | ||
const onInstance = 'onImsLibInstance'; | ||
|
||
const onImsReady = (timeout = 3000) => { | ||
existingCall = existingCall || new Promise((resolve, reject) => { | ||
const onFail = () => { | ||
if (!ready) reject(); | ||
}; | ||
const waitTimeout = setTimeout(onFail, timeout); | ||
const onSuccess = (data) => { | ||
const instance = data?.detail?.instance; | ||
if (!instance) { | ||
reject(); | ||
return; | ||
} | ||
|
||
ready = true; | ||
window.removeEventListener(onInstance, onSuccess); | ||
clearTimeout(waitTimeout); | ||
resolve(instance); | ||
}; | ||
|
||
window.addEventListener(onInstance, onSuccess); | ||
window.dispatchEvent(new window.CustomEvent('getImsLibInstance')); | ||
}); | ||
|
||
return existingCall; | ||
}; | ||
|
||
export default onImsReady; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters