file author : 王佳欣
 *  email import { EMPTY_FUNCTION } from '../constant' ; export const loadScript = ( src ) : Promise < any > => { return new Promise ( ( resolve , reject ) => { const timer = setTimeout ( ( ) => { reject ( 'error' ) ; } , 5000 ) ; const script = document . createElement ( 'script' ) ; script . type = 'text/javascript' ; script . src = src ; script . onload = ( ) => { clearTimeout ( timer ) ; resolve ( 'success' ) ; } ; script . onerror = ( ) => { clearTimeout ( timer ) ; reject ( 'error' ) ; } ; document . head . appendChild ( script ) ; } ) ; } ; export const loadImages = ( images , callback = EMPTY_FUNCTION ) : Promise < number > => { let haveLoadedCount = 0 ; return new Promise ( ( resolve , reject ) => { const loadedOne = ( ) => { haveLoadedCount ++ ; callback ( haveLoadedCount ) ; if ( haveLoadedCount === images . length ) { resolve ( haveLoadedCount ) ; } } ; const load = ( src ) : void => { const image = new Image ( ) ; image . onload = loadedOne ; image . onerror = loadedOne ; image . src = src ; } ; images . map ( load ) ; images . length === 0 && resolve ( 0 ) ; } ) ; } ;