Sha256: 7d9c3b14c90f22d58b46179dcec569313d6f20835fb767c40a1a7549aee465ae

Contents?: true

Size: 569 Bytes

Versions: 8

Compression:

Stored size: 569 Bytes

Contents

// Waits for condition to return true. If it returns false initially, this function creates a
// MutationObserver that calls body() whenever the contents of the component change.
export const observeMutationsUntilConditionMet = (element: Element, condition: () => boolean, body: () => void) => {
  if (condition()) {
    body()
  } else {
    const mutationObserver = new MutationObserver(() => {
      if (condition()) {
        body()
        mutationObserver.disconnect()
      }
    })

    mutationObserver.observe(element, {childList: true, subtree: true})
  }
}

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/components/primer/utils.ts
openproject-primer_view_components-0.52.2 app/components/primer/utils.ts
primer_view_components-0.36.4 app/components/primer/utils.ts
openproject-primer_view_components-0.52.1 app/components/primer/utils.ts
openproject-primer_view_components-0.52.0 app/components/primer/utils.ts
primer_view_components-0.36.3 app/components/primer/utils.ts
openproject-primer_view_components-0.51.0 app/components/primer/utils.ts
primer_view_components-0.36.2 app/components/primer/utils.ts