213 lines
6.5 KiB
JavaScript
213 lines
6.5 KiB
JavaScript
/**
|
|
* Internal class to represent a cached item
|
|
* Saves a reference to the original URL request
|
|
* and the content.
|
|
* @private
|
|
* @class CacheItem
|
|
* @memberof jibo.loader
|
|
* @param {String} request Full path requested
|
|
* @param {any} content Result of the load.
|
|
*/
|
|
|
|
/**
|
|
* Set of tokens referencing this asset.
|
|
* @name jibo.loader.CacheItem#tokens
|
|
* @type {Set<AssetToken>}
|
|
*/
|
|
|
|
/**
|
|
* Name and cache of items loaded from this item, so that they can be unloaded with it.
|
|
* @name jibo.loader.CacheItem#subAssets
|
|
* @type {AssetToken[]}
|
|
*/
|
|
|
|
/**
|
|
* The cached content.
|
|
* @name jibo.loader.CacheItem#content
|
|
* @type {any}
|
|
*/
|
|
|
|
/**
|
|
* Callbacks for completion of a pending load.
|
|
* @name jibo.loader.CacheItem#pendingCallbacks
|
|
* @type {Function[]}
|
|
*/
|
|
|
|
/**
|
|
* If the content variable contains an error rather than an actual result.
|
|
* @name jibo.loader.CacheItem#contentIsError
|
|
* @type {boolean}
|
|
*/
|
|
|
|
/**
|
|
* If the item load is currently in progress.
|
|
* @name jibo.loader.CacheItem#isPending
|
|
* @type {boolean}
|
|
* @readOnly
|
|
*/
|
|
|
|
/**
|
|
* Adds a callback to be called when the load completes.
|
|
* @method jibo.loader.CacheItem#addPending
|
|
* @param {jibo.loader.AssetToken} token Token attached to this callback
|
|
* @param {Function} callback Callback for when the load completes.
|
|
*/
|
|
|
|
/**
|
|
* Removes a pending callback.
|
|
* @method jibo.loader.CacheItem#removePending
|
|
* @param {Function} token Token of a pending asset load to remove.
|
|
*/
|
|
|
|
/**
|
|
* Adds the loaded content and any subAssets loaded during the load.
|
|
* @method jibo.loader.CacheItem#completeLoad
|
|
*/
|
|
|
|
/**
|
|
* Destroy the content, don't use after this.
|
|
* @method jibo.loader.CacheItem#destroy
|
|
* @param {jibo.loader.AssetCache} cache The main asset cache so that sub assets can be unloaded.
|
|
*/
|
|
|
|
/**
|
|
* Internal class to represent a specific cache that items are loaded into. This allows for easier
|
|
* unloading of a whole group of items.
|
|
* @private
|
|
* @class NamedCache
|
|
* @memberof jibo.loader
|
|
* @param {String} name Name of the cache.
|
|
*/
|
|
|
|
/**
|
|
* The name of the cache.
|
|
* @type {String}
|
|
* @name jibo.loader.NamedCache#name
|
|
*/
|
|
|
|
/**
|
|
* A map of asset ids to asset keys.
|
|
* @type {Object}
|
|
* @name jibo.loader.NamedCache#idMap
|
|
*/
|
|
|
|
/**
|
|
* The set of loads attached to this cache.
|
|
* @type {Object}
|
|
* @name jibo.loader.NamedCache#tokens
|
|
*/
|
|
|
|
/**
|
|
* Marks an item as loaded one time within this cache.
|
|
* @method jibo.loader.NamedCache#load
|
|
* @param {jibo.loader.AssetToken} token Shorthand id that the item was loaded under.
|
|
*/
|
|
|
|
/**
|
|
* Removes one loaded mark for an item within this cache.
|
|
* @method jibo.loader.NamedCache#unload
|
|
* @param {jibo.loader.AssetToken} token Token by which
|
|
*/
|
|
|
|
/**
|
|
* Manages a cache for assets.
|
|
* @class AssetCache
|
|
* @memberof jibo.loader
|
|
* @private
|
|
*/
|
|
|
|
/**
|
|
* The cache containing assets.
|
|
* @type {Object}
|
|
* @name jibo.loader.AssetCache#_cache
|
|
*/
|
|
|
|
/**
|
|
* A map of the current named caches
|
|
* @type {Object}
|
|
* @name jibo.loader.AssetCache#_cachesMap
|
|
*/
|
|
|
|
/**
|
|
* A reference to the owning asset manager.
|
|
* @type {jibo.loader.AssetManager}
|
|
* @name jibo.loader.AssetCache#_manager
|
|
*/
|
|
|
|
/**
|
|
* Add a named cache to load items with.
|
|
* @method jibo.loader.AssetCache#addCache
|
|
* @param {String} id The cache id to add.
|
|
*/
|
|
|
|
/**
|
|
* Retrieves a single asset from the cache.
|
|
* @method jibo.loader.AssetCache#read
|
|
* @param {String} id The asset to get. If no cacheId, then this must be the unique id (usually the absolute source path).
|
|
* @param {String} [cacheId] Cache ID to specify.
|
|
* @return {any} Result or null, if no asset
|
|
*/
|
|
|
|
/**
|
|
* Dermines if a single asset from the cache is loaded or not.
|
|
* @method jibo.loader.AssetCache#isLoaded
|
|
* @param {String} id The asset to get. If no cacheId, then this must be the unique id (usually the absolute source path).
|
|
* @param {String} [cacheId] Cache ID to specify.
|
|
* @return {boolean} If the item is fully loaded
|
|
*/
|
|
|
|
/**
|
|
* Determines if a single asset from the cache has been loaded, but was a failure to load.
|
|
* @method jibo.loader.AssetCache#wasError
|
|
* @param {String} id The asset to get. If no cacheId, then this must be the unique id (usually the absolute source path).
|
|
* @param {String} [cacheId] Cache ID to specify.
|
|
* @return {boolean} If the item is fully loaded but was an error
|
|
*/
|
|
|
|
/**
|
|
* Prepares a single asset in the cache to have content written later.
|
|
* @method jibo.loader.AssetCache#prepare
|
|
* @param {string} key Unique key that the asset will be stored under.
|
|
* @param {string} cacheName Name of the named cache that the asset will be stored under.
|
|
* @param {string} id Id that the asset will be stored in the named cache under.
|
|
* @returns {jibo.loader.AssetToken} A unique token representing this load of the asset. Use this to unload the asset later.
|
|
*/
|
|
|
|
/**
|
|
* Prepares a single asset in the cache to have content written later.
|
|
* @method jibo.loader.AssetCache#addPending
|
|
* @param {AssetToken} token The AssetResult type object from the AssetLoad.
|
|
* @param {Function} callback Callback to call when the asset has been loaded.
|
|
* @returns {boolean} true if this was the first pending callback added, false if it was already pending
|
|
*/
|
|
|
|
/**
|
|
* Removes a callback from a pending item.
|
|
* @method jibo.loader.AssetCache#cancelPending
|
|
* @param {jibo.loader.AssetToken} token The token that was created when the asset began loading.
|
|
*/
|
|
|
|
/**
|
|
* Adds loaded content to an item in the cache, and tells it to call pending callbacks.
|
|
* @method jibo.loader.AssetCache#completePending
|
|
* @param {any} err A load error.
|
|
* @param {AssetResult} result The AssetResult type object from the AssetLoad.
|
|
*/
|
|
|
|
/**
|
|
* Removes a single asset from the cache.
|
|
* @method jibo.loader.AssetCache#delete
|
|
* @param {Object|String} assetOrId The asset to remove, or id of asset.
|
|
* @param {String} cacheId Cache to specify
|
|
*/
|
|
|
|
/**
|
|
* Removes all assets from the cache.
|
|
* @method jibo.loader.AssetCache#empty
|
|
* @param {string} [cacheId] The optional cache
|
|
*/
|
|
|
|
/**
|
|
* Destroys the cache. Don't use after this.
|
|
* @method jibo.loader.AssetCache#destroy
|
|
*/ |