MCPcopy Create free account
hub / github.com/ampproject/amphtml / getStorage

Method getStorage

extensions/amp-script/0.1/amp-script.js:860–880  ·  view source on GitHub ↗

* TODO(choumx): Make this method always return a Promise. * @param {!StorageLocation} location * @param {string} opt_key * @return {!Promise |?Object}

(location, opt_key)

Source from the content-addressed store, hash-verified

858 * @return {!Promise<Object>|?Object}
859 */
860 getStorage(location, opt_key) {
861 if (location === StorageLocation.AMP_STATE) {
862 return Services.bindForDocOrNull(this.element_).then((bind) => {
863 if (bind) {
864 return bind.getStateValue(opt_key || '.');
865 }
866 });
867 }
868 // Note that filtering out amp-* keys will affect the predictability of
869 // Storage.key(). We could preserve indices by adding empty entries but
870 // that might be even more confusing.
871 const storage = this.storageFor_(location);
872 const output = {};
873 for (let i = 0; i < storage.length; i++) {
874 const key = storage.key(i);
875 if (key && !key.startsWith('amp-')) {
876 output[key] = storage.getItem(key);
877 }
878 }
879 return output;
880 }
881
882 /**
883 * @param {!StorageLocation} location

Callers 1

test-amp-script.jsFile · 0.80

Calls 5

storageFor_Method · 0.95
getStateValueMethod · 0.80
keyMethod · 0.80
getItemMethod · 0.80
thenMethod · 0.45

Tested by

no test coverage detected