mirror of
https://github.com/scratchfoundation/scratch-storage.git
synced 2025-08-14 07:20:52 -04:00
Add docstrings
This commit is contained in:
parent
a00562cbca
commit
15b6a16af3
2 changed files with 19 additions and 0 deletions
|
@ -70,6 +70,12 @@ class BuiltinHelper extends Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously fetch a cached asset for a given asset id. Returns null if not found.
|
||||||
|
* @param {string} assetId - The id for the asset to fetch.
|
||||||
|
* @returns {?Asset} The asset for assetId, if it exists.
|
||||||
|
*/
|
||||||
get (assetId) {
|
get (assetId) {
|
||||||
let asset = null;
|
let asset = null;
|
||||||
if (this.assets.hasOwnProperty(assetId)) {
|
if (this.assets.hasOwnProperty(assetId)) {
|
||||||
|
@ -80,6 +86,14 @@ class BuiltinHelper extends Helper {
|
||||||
return asset;
|
return asset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache an asset for future lookups by ID.
|
||||||
|
* @param {AssetType} assetType - The type of the asset to cache.
|
||||||
|
* @param {DataFormat} dataFormat - The dataFormat of the data for the cached asset.
|
||||||
|
* @param {Buffer} data - The data for the cached asset.
|
||||||
|
* @param {string} id - The id for the cached asset.
|
||||||
|
* @returns {string} The calculated id of the cached asset, or the supplied id if the asset is mutable.
|
||||||
|
*/
|
||||||
cache (assetType, dataFormat, data, id) {
|
cache (assetType, dataFormat, data, id) {
|
||||||
if (!dataFormat) throw new Error('Data cached without specifying its format');
|
if (!dataFormat) throw new Error('Data cached without specifying its format');
|
||||||
if (id) {
|
if (id) {
|
||||||
|
|
|
@ -49,6 +49,11 @@ class ScratchStorage {
|
||||||
return AssetType;
|
return AssetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously fetch a cached asset from built-in storage. Assets are cached when they are loaded.
|
||||||
|
* @param {string} assetId - The id of the asset to fetch.
|
||||||
|
* @returns {?Asset} The asset, if it exists.
|
||||||
|
*/
|
||||||
get (assetId) {
|
get (assetId) {
|
||||||
return this.builtinHelper.get(assetId);
|
return this.builtinHelper.get(assetId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue