( childId: string, callback: (el: Element) => void, root?: Document | ShadowRoot )
| 858 | * @public |
| 859 | */ |
| 860 | export function whenAvailable( |
| 861 | childId: string, |
| 862 | callback: (el: Element) => void, |
| 863 | root?: Document | ShadowRoot |
| 864 | ): void { |
| 865 | if (!isBrowser) return |
| 866 | if (!root) root = document |
| 867 | const el = root.getElementById(childId) |
| 868 | if (el) return callback(el) |
| 869 | const observer = new MutationObserver(() => { |
| 870 | const el = root?.getElementById(childId) |
| 871 | if (el) { |
| 872 | observer?.disconnect() |
| 873 | callback(el) |
| 874 | } |
| 875 | }) |
| 876 | observer.observe(root, { childList: true, subtree: true }) |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Given a function only 1 call will be made per call stack. All others will |
no test coverage detected