UNPKG

@j2inn/app

Version:

J2 Innovations core application framework

46 lines (45 loc) 1.5 kB
export interface Callback { (): void; } /** * Handles loading a resource DOM element and listening for when it's * finished or failed to load. * * This is designed to handle race conditions whereby a resource * added but not yet fully loaded. Event handlers can be registered * even after a resource has loaded with event handlers being fired. */ export declare class ResourceElement { #private; ready: boolean; failed: boolean; constructor(resource: HTMLScriptElement | HTMLLinkElement); /** * A callback made by the resource DOM element for * when the resource has loaded successfully. */ private onload; /** * A callback made by the resource DOM element for * when the resource fails to load. */ private onerror; /** * Add event listeners for when a resource has loaded or failed to load. * * @param onLoad A callback for when the resource has loaded successfully. * @param onError A callback for when the resource has failed to load. */ addListeners(onLoad: Callback, onError: Callback): void; /** * Removes load and error event listeners. * * @param onLoad A callback for when the resource has loaded successfully. * @param onError A callback for when the resource has failed to load. */ removeListeners(onLoad: Callback, onError: Callback): void; /** * Checks whether any callback handlers need to be invoked. */ private checkLoaded; }