@luma.gl/core
Version:
The luma.gl core Device API
36 lines • 1.23 kB
JavaScript
// luma.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import { isBrowser } from '@probe.gl/env';
/**
* Create and attach devices for a specific backend.
*/
export class Adapter {
/**
* Page load promise
* Resolves when the DOM is loaded.
* @note Since are be limitations on number of `load` event listeners,
* it is recommended avoid calling this accessor until actually needed.
* I.e. we don't call it unless you know that you will be looking up a string in the DOM.
*/
get pageLoaded() {
return getPageLoadPromise();
}
}
// HELPER FUNCTIONS
const isPage = isBrowser() && typeof document !== 'undefined';
const isPageLoaded = () => isPage && document.readyState === 'complete';
let pageLoadPromise = null;
/** Returns a promise that resolves when the page is loaded */
function getPageLoadPromise() {
if (!pageLoadPromise) {
if (isPageLoaded() || typeof window === 'undefined') {
pageLoadPromise = Promise.resolve();
}
else {
pageLoadPromise = new Promise(resolve => window.addEventListener('load', () => resolve()));
}
}
return pageLoadPromise;
}
//# sourceMappingURL=adapter.js.map