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

Method fastScan_

extensions/amp-bind/0.1/bind-impl.js:485–521  ·  view source on GitHub ↗

* @param {!Array<!Element>} addedElements * @param {!Array<!Element>} removedElements * @return {!Promise} * @private

(addedElements, removedElements)

Source from the content-addressed store, hash-verified

483 * @private
484 */
485 fastScan_(addedElements, removedElements) {
486 // Sync remove bindings from internal state first, but don't chain on
487 // returned promise (worker message) as an optimization.
488 const removePromise = this.removeBindingsForNodes_(removedElements);
489
490 // Scan `addedElements` and descendants for bindings.
491 const bindings = [];
492 const elementsToScan = addedElements.filter((el) =>
493 el.hasAttribute('i-amphtml-binding')
494 );
495 addedElements.forEach((el) => {
496 const children = el.querySelectorAll('[i-amphtml-binding]');
497 Array.prototype.push.apply(elementsToScan, children);
498 });
499 const quota = this.maxNumberOfBindings_ - this.numberOfBindings();
500 for (let i = 0; i < elementsToScan.length; i++) {
501 const el = elementsToScan[i];
502 if (this.scanElement_(el, quota - bindings.length, bindings)) {
503 break;
504 }
505 }
506
507 removePromise.then((removed) => {
508 dev().info(
509 TAG,
510 'rescan.fast: delta=%s, total=%s',
511 bindings.length - removed,
512 this.numberOfBindings()
513 );
514 });
515
516 if (bindings.length > 0) {
517 return this.sendBindingsToWorker_(bindings);
518 } else {
519 return Promise.resolve();
520 }
521 }
522
523 /**
524 * Returns a copy of the global state for a given field-based expression,

Callers 1

rescan_Method · 0.95

Calls 11

numberOfBindingsMethod · 0.95
scanElement_Method · 0.95
sendBindingsToWorker_Method · 0.95
devFunction · 0.90
applyMethod · 0.80
infoMethod · 0.80
resolveMethod · 0.80
filterMethod · 0.45
forEachMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected