Skip to content

Commit

Permalink
refactor: use forEach method instead of for-of
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukkee committed Sep 12, 2024
1 parent d601d4d commit 3263b4e
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions packages/utilities/dismissable/src/pointer-event-outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,35 @@ export function disablePointerEventsOutside(node: HTMLElement, persistentElement
const persistedElementsMap = new Map<HTMLElement, () => void>()
const persistedCleanup = observeChildren(doc.body, {
callback: (records) => {
for (const record of records) {
if (record.type !== "childList") continue
records.forEach((record) => {
if (record.type !== "childList") return

for (const node of record.addedNodes) {
for (const fn of persistentElements) {
record.addedNodes.forEach((node) => {
persistentElements.forEach((fn) => {
const el = fn()
if (isHTMLElement(el) && node.contains(el)) {
const cleanup = setStyle(el, { pointerEvents: "auto" })
persistedElementsMap.set(el, cleanup)
cleanups.push(cleanup)
}
}
}
})
})

for (const node of record.removedNodes) {
for (const [el, cleanup] of persistedElementsMap.entries()) {
record.removedNodes.forEach((node) => {
persistedElementsMap.forEach((cleanup, el) => {
if (node.contains(el)) {
cleanup()
persistedElementsMap.delete(el)
const index = cleanups.indexOf(cleanup)
if (index > -1) {
cleanups.splice(index, 1)
}
}
}
}
}
})
})
})
},
})
cleanups.push(persistedCleanup)
cleanups.push(() => persistedElementsMap.clear())
cleanups.push(() => {
persistedElementsMap.forEach((cleanup) => cleanup())
persistedElementsMap.clear()
persistedCleanup()
})
}

return () => {
Expand Down

0 comments on commit 3263b4e

Please sign in to comment.