MCPcopy Index your code
hub / github.com/ampproject/amphtml / set

Method set

src/service/storage-impl.js:237–276  ·  view source on GitHub ↗

* Set the storage value along with the current timestamp. * When opt_isUpdated is true, timestamp will be the creation timestamp, * the stored value will be updated w/o updating timestamp. * @param {string} name * @param {*} value * @param {boolean=} opt_isUpdate

(name, value, opt_isUpdate)

Source from the content-addressed store, hash-verified

235 * @param {boolean=} opt_isUpdate
236 */
237 set(name, value, opt_isUpdate) {
238 devAssert(
239 name != '__proto__' && name != 'prototype',
240 'Name is not allowed: %s',
241 name
242 );
243 // The structure is {key: {v: *, t: time}}
244 if (this.values_[name] !== undefined) {
245 const item = this.values_[name];
246 let timestamp = Date.now();
247 if (opt_isUpdate) {
248 // Update value w/o timestamp
249 timestamp = item['t'];
250 }
251 item['v'] = value;
252 item['t'] = timestamp;
253 } else {
254 this.values_[name] = {
255 'v': value,
256 't': Date.now(),
257 };
258 }
259
260 // Purge old values.
261 const keys = Object.keys(this.values_);
262 if (keys.length > this.maxValues_) {
263 let minTime = Infinity;
264 let minKey = null;
265 for (let i = 0; i < keys.length; i++) {
266 const item = this.values_[keys[i]];
267 if (item['t'] < minTime) {
268 minKey = keys[i];
269 minTime = item['t'];
270 }
271 }
272 if (minKey) {
273 delete this.values_[minKey];
274 }
275 }
276 }
277
278 /**
279 * @param {string} name

Callers 10

prepend_Method · 0.45
optOutOfCidFunction · 0.45
initializeMethod · 0.45
scheduleAsapMethod · 0.45
scheduleMethod · 0.45
setContainerMethod · 0.45
observed_Method · 0.45
elementConnectedCallbackFunction · 0.45
setNonBooleanMethod · 0.45
inViewport_Method · 0.45

Calls 2

devAssertFunction · 0.90
nowMethod · 0.80

Tested by

no test coverage detected