UNPKG

cwt-map

Version:
58 lines (57 loc) 1.9 kB
import Promise = require("bluebird"); export interface ScriptState { _callbacks?: Array<() => void>; hasLoaded: boolean; wasRejected: boolean; error?: any; promise: Promise<ScriptState>; tag: HTMLScriptElement; } /** * map for script names against utility objects * @type {Map<string, ScriptState>} */ export declare const loadedScripts: Map<string, ScriptState>; /** * script tags to be generated by the cache method * @type {{}} */ export declare const scriptTags: ScriptTags; export interface Scripts { [name: string]: string; } export declare type Callback = (error: any, result?: any) => void; export declare type AllCallback = (errors: any[], results?: any[]) => void; export interface ScriptTag { name: string; script: string; tag: HTMLScriptElement; onLoad(callback: Callback): void; } export interface ScriptTags { [name: string]: ScriptTag; } /** * * @param scripts {Scripts} - An object with all the scripts required. Keys are script names, values are URLs. */ export declare function cache(scripts: Scripts): void; export declare function getScriptStub(name: string): ScriptTag; /** * Callback to be fired when each script has loaded. * @param name {string} - The name of the string that has just loaded. * @param callback {Callback} - A callback to execute when the script has loaded. */ export declare function onLoad(name: string, callback: Callback): void; /** * Callback to be fired when all scripts have loaded * @param callback {Function} - The callback to be executed. */ export declare function onAllLoad(callback: AllCallback): void; /** * Get a script from a remote location. * @param name {string} - The name of the script to be retrieved. * @param url {string} - The URL/location of the script to be retrieved. */ export declare function getScript(url: string, name: string): ScriptState; export default cache;