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

Method startUsed_

src/core/context/values.js:363–418  ·  view source on GitHub ↗

* Start the used value tracker if it hasn't started yet. * * @param {IContextProp } prop * @return {IContextPropUsed } * @private * @template T, DEP

(prop)

Source from the content-addressed store, hash-verified

361 * @template T, DEP
362 */
363 startUsed_(prop) {
364 const {deps, key} = prop;
365 const usedByKey = this.usedByKey_ || (this.usedByKey_ = new Map());
366 let used = usedByKey.get(key);
367 if (!used) {
368 used = {
369 prop,
370 subscribers: [],
371 value: undefined,
372 pending: Pending_Enum.NOT_PENDING,
373 counter: 0,
374 depValues: deps.length > 0 ? deps.map(EMPTY_FUNC) : EMPTY_ARRAY,
375 parentValue: undefined,
376 parentContextNode: null,
377 // Schedule the value recalculation, optionally with the parent
378 // refresh.
379 /** @type {function(boolean):void} */
380 ping: (refreshParent) => {
381 if (this.isConnected_()) {
382 const pending = refreshParent
383 ? Pending_Enum.PENDING_REFRESH_PARENT
384 : Pending_Enum.PENDING;
385 used.pending = Math.max(used.pending, pending);
386 this.checkUpdates_();
387 }
388 },
389 // Schedule the value recalculation due to the dependency change.
390 pingDep:
391 deps.length > 0
392 ? deps.map((dep, index) => {
393 /** @param {DEP} value*/
394 return (value) => {
395 used.depValues[index] = value;
396 used.ping();
397 };
398 })
399 : EMPTY_ARRAY,
400 // Schedule the value recalculation due to the parent value change.
401 pingParent: isRecursive(prop)
402 ? /** @param {T} parentValue */
403 (parentValue) => {
404 used.parentValue = parentValue;
405 used.ping();
406 }
407 : null,
408 };
409 usedByKey.set(key, used);
410
411 // Subscribe to all deps.
412 deps.forEach((dep, index) => this.subscribe(dep, used.pingDep[index]));
413
414 // Schedule the first refresh.
415 used.ping(false);
416 }
417 return used;
418 }
419
420 /**

Callers 1

subscribeMethod · 0.95

Calls 8

isConnected_Method · 0.95
checkUpdates_Method · 0.95
subscribeMethod · 0.95
isRecursiveFunction · 0.85
pingMethod · 0.80
getMethod · 0.45
setMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected