Skip to content

Commit

Permalink
Use setTimeout(0) on events with void return type
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed Aug 28, 2024
1 parent 8a3b4ac commit 85f7bd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/child/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function iframeResizerChild() {

sendTitle()
initEventListeners()
onReady()
setTimeout(onReady)

log('Initialization complete')
log('---')
Expand Down Expand Up @@ -1285,7 +1285,7 @@ The <b>size()</> method has been deprecated and replaced with <b>resize()</>. U
const msgBody = getData()
log(`PageInfo received from parent: ${msgBody}`)
if (onPageInfo) {
onPageInfo(JSON.parse(msgBody))
setTimeout(() => onPageInfo(JSON.parse(msgBody)))
} else {
// not expected, so cancel more messages
sendMsg(0, 0, 'pageInfoStop')
Expand All @@ -1297,7 +1297,7 @@ The <b>size()</> method has been deprecated and replaced with <b>resize()</>. U
const msgBody = getData()
log(`ParentInfo received from parent: ${msgBody}`)
if (onParentInfo) {
onParentInfo(Object.freeze(JSON.parse(msgBody)))
setTimeout(onParentInfo(Object.freeze(JSON.parse(msgBody))))
} else {
// not expected, so cancel more messages
sendMsg(0, 0, 'parentInfoStop')
Expand Down
8 changes: 4 additions & 4 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,13 +676,13 @@ function chkEvent(iframeId, funcName, val) {
if (settings[iframeId]) {
func = settings[iframeId][funcName]

if (typeof func === 'function') {
retVal = func(val)
} else {
if (typeof func === 'function')
if (funcName === 'onClose' || funcName === 'onScroll') retVal = func(val)
else setTimeout(() => func(val))
else
throw new TypeError(
`${funcName} on iFrame[${iframeId}] is not a function`,
)
}
}

return retVal
Expand Down

0 comments on commit 85f7bd5

Please sign in to comment.