packages/mip/src/util/dom/dom.js
function onDocumentState (doc, stateFn, callback) {
  let ready = stateFn(doc)

  if (ready) {
    callback(doc)

    return
  }

  const readyListener = () => {
    if (!stateFn(doc)) {
      return
    }

    if (!ready) {
      ready = true
      callback(doc)
    }

    doc.removeEventListener('readystatechange', readyListener)
  }

  doc.addEventListener('readystatechange', readyListener)
}
function onDocumentState (doc, stateFn, callback) {
  let ready = stateFn(doc)

  if (ready) {
    callback(doc)

    return
  }

  const readyListener = () => {
    if (!stateFn(doc)) {
      return
    }

    if (!ready) {
      ready = true
      callback(doc)
    }

    doc.removeEventListener('readystatechange', readyListener)
  }

  doc.addEventListener('readystatechange', readyListener)
}
function onDocumentState ( doc , stateFn , callback ) { let ready = stateFn ( doc ) if ( ready ) { callback ( doc ) return } const readyListener = ( ) => { if ( ! stateFn ( doc ) ) { return } if ( ! ready ) { ready = true callback ( doc ) } doc . removeEventListener ( 'readystatechange' , readyListener ) } doc . addEventListener ( 'readystatechange' , readyListener ) }
Calls the callback when document's state satisfies the stateFn.

@param {!Document} doc
@param {(doc: Document) => boolean} stateFn
@param {(doc: Document) => void} callback
Calls the callback when document s state satisfies the stateFn .