src/asset-loader.js
/**
   * Loads a single asset.
   *
   * @param {String} url  The url of the asset to load.
   * @param {String} type The type of asset being requested
   *
   * @returns { Promise }  Returns a promise.  Resolves immediately
   *                       if the asset it already loaded.
   * @see AssetLoader.loadResource
   */
Loads a single asset.
@param {String} url  The url of the asset to load.
@param {String} type The type of asset being requested

@returns { Promise }  Returns a promise.  Resolves immediately
if the asset it already loaded.
Loads a single asset . @param { String } url The url of the asset to load . @param { String } type The type of asset being requested @returns { Promise } Returns a promise . Resolves immediately if the asset it already loaded .
loadAsset(url, type) {
    var name = '_' + encodeURIComponent(url);
    if(this._assets[name])
    {
      return Promise.resolve(this._assets[name]);
    }
    else
    {
      return new Promise((resolve, reject) => {
        this._callbacks[name] = this._callbacks[name] || [];
        this._callbacks[name].push({resolve, reject});
        if(!this._assets.hasOwnProperty(name))
        {
          this._assets[name] = false;
          AssetLoader.loadResource(url, type).then((value) => {
            this._assets[name] = value;
            var cb;
            while((cb = this._callbacks[name].shift()))
            {
              cb.resolve(value);
            }
          }).catch((err) => {
            var cb;
            while((cb = this._callbacks[name].shift()))
            {
              cb.reject(err);
            }
          });
        }
      });
    }
  }
loadAsset ( url , type ) { var name = '_' + encodeURIComponent ( url ) ; if ( this . _assets [ name ] ) { return Promise . resolve ( this . _assets [ name ] ) ; } else { return new Promise ( ( resolve , reject ) => { this . _callbacks [ name ] = this . _callbacks [ name ] || [ ] ; this . _callbacks [ name ] . push ( { resolve , reject } ) ; if ( ! this . _assets . hasOwnProperty ( name ) ) { this . _assets [ name ] = false ; AssetLoader . loadResource ( url , type ) . then ( ( value ) => { this . _assets [ name ] = value ; var cb ; while ( ( cb = this . _callbacks [ name ] . shift ( ) ) ) { cb . resolve ( value ) ; } } ) . catch ( ( err ) => { var cb ; while ( ( cb = this . _callbacks [ name ] . shift ( ) ) ) { cb . reject ( err ) ; } } ) ; } } ) ; } }
Loads a single asset.
Loads a single asset .