* TODO(choumx): Make this method always return a Promise. * @param {!StorageLocation} location * @param {string} opt_key * @return {!Promise |?Object}
(location, opt_key)
| 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 |
no test coverage detected