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

Function createCustomElementClass

src/custom-element.js:93–114  ·  view source on GitHub ↗
(win, elementConnectedCallback)

Source from the content-addressed store, hash-verified

91 * @return {typeof AmpElement} The custom element class.
92 */
93export function createCustomElementClass(win, elementConnectedCallback) {
94 const BaseCustomElement = /** @type {typeof HTMLElement} */ (
95 createBaseCustomElementClass(win, elementConnectedCallback)
96 );
97 // It's necessary to create a subclass, because the same "base" class cannot
98 // be registered to multiple custom elements.
99 class CustomAmpElement extends BaseCustomElement {
100 /**
101 * adoptedCallback is only called when using a Native implementation of Custom Elements V1.
102 * Our polyfill does not call this method.
103 */
104 adoptedCallback() {
105 // Work around an issue with Firefox changing the prototype of our
106 // already constructed element to the new document's HTMLElement.
107 if (Object.getPrototypeOf(this) !== customAmpElementProto) {
108 Object.setPrototypeOf(this, customAmpElementProto);
109 }
110 }
111 }
112 const customAmpElementProto = CustomAmpElement.prototype;
113 return /** @type {typeof AmpElement} */ (CustomAmpElement);
114}
115
116/**
117 * Creates a base custom element class.

Callers 2

registerElementFunction · 0.90

Calls 1

Tested by

no test coverage detected