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

Method mutationPump_

extensions/amp-script/0.1/amp-script.js:509–545  ·  view source on GitHub ↗

* @param {function(boolean)} flush If `flush(false)` is invoked, mutations * that cause user-visible changes (e.g. DOM changes) will be dropped * (changes like event listener registration will be kept). * @param {number} phase * @private

(flush, phase)

Source from the content-addressed store, hash-verified

507 * @private
508 */
509 mutationPump_(flush, phase) {
510 if (phase == Phase.HYDRATING) {
511 this.vsync_.mutate(() =>
512 this.element.classList.add('i-amphtml-hydrated')
513 );
514 }
515 const allowMutation =
516 this.isMutationAllowedByFixedSize() ||
517 this.isMutationAllowedByUserGesture();
518
519 this.vsync_.mutate(() => {
520 const disallowedTypes = flush(allowMutation);
521 // Count the number of mutations dropped by type.
522 const errors = map();
523 /** @type {!Array} */ (disallowedTypes).forEach((type) => {
524 errors[type] = errors[type] + 1 || 1;
525 });
526 // Emit an error message for each mutation type, including count.
527 Object.keys(errors).forEach((type) => {
528 const count = errors[type];
529 user().error(TAG, this.mutationTypeToErrorMessage_(type, count));
530 });
531
532 if (disallowedTypes.length > 0 && phase === Phase.MUTATING) {
533 this.workerDom_.terminate();
534
535 this.element.classList.remove('i-amphtml-hydrated');
536 this.element.classList.add('i-amphtml-broken');
537
538 user().error(
539 TAG,
540 '%s was terminated due to illegal mutation.',
541 this.debugId_
542 );
543 }
544 });
545 }
546
547 /**
548 * @param {string} type

Callers

nothing calls this directly

Calls 11

mapFunction · 0.90
userFunction · 0.90
flushFunction · 0.50
mutateMethod · 0.45
addMethod · 0.45
forEachMethod · 0.45
errorMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected