packages/mip/src/util/dom/event.js
function loadPromise (eleOrWindow) {
  if (isLoaded(eleOrWindow)) {
    return Promise.resolve(eleOrWindow)
  }

  let loadingPromise = new Promise((resolve, reject) => {
    // Listen once since IE 5/6/7 fire the onload event continuously for
    // animated GIFs.
    let {tagName} = eleOrWindow
    if (tagName === 'AUDIO' || tagName === 'VIDEO') {
      listenOnce(eleOrWindow, 'loadstart', resolve)
    } else {
      listenOnce(eleOrWindow, 'load', resolve)
    }
    // For elements, unlisten on error (don't for Windows).
    if (tagName) {
      listenOnce(eleOrWindow, 'error', reject)
    }
  })

  return loadingPromise
}
function loadPromise (eleOrWindow) {
  if (isLoaded(eleOrWindow)) {
    return Promise.resolve(eleOrWindow)
  }

  let loadingPromise = new Promise((resolve, reject) => {
    // Listen once since IE 5/6/7 fire the onload event continuously for
    // animated GIFs.
    let {tagName} = eleOrWindow
    if (tagName === 'AUDIO' || tagName === 'VIDEO') {
      listenOnce(eleOrWindow, 'loadstart', resolve)
    } else {
      listenOnce(eleOrWindow, 'load', resolve)
    }
    // For elements, unlisten on error (don't for Windows).
    if (tagName) {
      listenOnce(eleOrWindow, 'error', reject)
    }
  })

  return loadingPromise
}
function loadPromise ( eleOrWindow ) { if ( isLoaded ( eleOrWindow ) ) { return Promise . resolve ( eleOrWindow ) } let loadingPromise = new Promise ( ( resolve , reject ) => { // Listen once since IE 5/6/7 fire the onload event continuously for // animated GIFs. let { tagName } = eleOrWindow if ( tagName === 'AUDIO' || tagName === 'VIDEO' ) { listenOnce ( eleOrWindow , 'loadstart' , resolve ) } else { listenOnce ( eleOrWindow , 'load' , resolve ) } // For elements, unlisten on error (don't for Windows). if ( tagName ) { listenOnce ( eleOrWindow , 'error' , reject ) } } ) return loadingPromise }
Returns a promise that will resolve or fail based on the eleOrWindow's 'load'
and 'error' events. Optionally this method takes a timeout, which will reject
the promise if the resource has not loaded by then.
@param {T} eleOrWindow Supports both Elements and as a special case Windows.
@return {!Promise<T>}
@template T
Returns a promise that will resolve or fail based on the eleOrWindow s load and error events . Optionally this method takes a timeout which will reject the promise if the resource has not loaded by then .