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

Method initialize_

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

* Scans the root node (and array of optional nodes) for bindings. * @param {!Node} root * @return {!Promise} * @private

(root)

Source from the content-addressed store, hash-verified

585 * @private
586 */
587 initialize_(root) {
588 // Disallow URL property bindings in AMP4EMAIL.
589 const allowUrlProperties = !isAmp4Email(this.localWin_.document);
590 this.validator_ = new BindValidator(allowUrlProperties);
591
592 // The web worker's evaluator also has an instance of BindValidator
593 // that should be initialized with the same `allowUrlProperties` value.
594 return this.ww_('bind.init', [allowUrlProperties])
595 .then(() => {
596 return Promise.all([
597 this.addMacros_().then(() => this.addMacrosDeferred_.resolve()),
598 this.addBindingsForNodes_([root]),
599 ]);
600 })
601 .then(() => {
602 // Listen for DOM updates (e.g. template render) to rescan for bindings.
603 root.addEventListener(AmpEvents_Enum.DOM_UPDATE, (e) =>
604 this.onDomUpdate_(e)
605 );
606 })
607 .then(() => {
608 const ampStates = root.querySelectorAll('AMP-STATE');
609 // Force all query-able <amp-state> elements to parse local data instead
610 // of waiting for runtime to build them all.
611 const whenBuilt = false;
612 const whenParsed = toArray(ampStates).map((el) => {
613 return whenUpgradedToCustomElement(el)
614 .then(() => el.getImpl(whenBuilt))
615 .then((impl) => impl.parseAndUpdate());
616 });
617 return Promise.all(whenParsed);
618 })
619 .then(() => {
620 // Bind is "ready" when its initialization completes _and_ all <amp-state>
621 // elements' local data is parsed and processed (not remote data).
622 this.viewer_.sendMessage('bindReady', undefined);
623 this.dispatchEventForTesting_(BindEvents.INITIALIZE);
624
625 // In dev mode, check default values against initial expression results.
626 if (getMode().development) {
627 return this.evaluate_().then((results) => this.verify_(results));
628 }
629 });
630 }
631
632 /**
633 * The current number of bindings.

Callers 1

constructorMethod · 0.95

Calls 15

ww_Method · 0.95
addMacros_Method · 0.95
addBindingsForNodes_Method · 0.95
onDomUpdate_Method · 0.95
evaluate_Method · 0.95
verify_Method · 0.95
isAmp4EmailFunction · 0.90
toArrayFunction · 0.90
getModeFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected