* @param {!Array<!Element>} addedElements * @param {!Array<!Element>} removedElements * @return {!Promise} * @private
(addedElements, removedElements)
| 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, |
no test coverage detected