-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
48c6caf
commit a510334
Showing
7 changed files
with
131 additions
and
19 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,27 @@ | ||
import { getWindow } from "@zag-js/dom-query" | ||
|
||
export const waitForFn = (rootNode: Document | ShadowRoot) => { | ||
return function waitFor(fn: () => boolean | undefined) { | ||
return new Promise<void>((resolve, reject) => { | ||
const win = getWindow(rootNode) | ||
|
||
const observer = new win.MutationObserver(() => { | ||
if (fn()) { | ||
resolve() | ||
observer.disconnect() | ||
} | ||
}) | ||
|
||
observer.observe(rootNode, { | ||
childList: true, | ||
subtree: true, | ||
characterData: true, | ||
}) | ||
|
||
setTimeout(() => { | ||
observer.disconnect() | ||
reject(new Error("Timeout")) | ||
}, 3000) | ||
}) | ||
} | ||
} |
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