MCPcopy Create free account
hub / github.com/formkit/formkit / whenAvailable

Function whenAvailable

packages/utils/src/index.ts:860–877  ·  view source on GitHub ↗
(
  childId: string,
  callback: (el: Element) => void,
  root?: Document | ShadowRoot
)

Source from the content-addressed store, hash-verified

858 * @public
859 */
860export 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

Callers 3

autoHeightTextareaPluginFunction · 0.90
multiStepPluginFunction · 0.90
floatingLabelsPluginFunction · 0.90

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected