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

Function createBentoElementClass

src/preact/bento-ce.js:89–125  ·  view source on GitHub ↗

* @param {typeof import('./base-element').PreactBaseElement} BaseElement * @param {typeof globalThis} _win * @return {typeof HTMLElement} * @template {{ * readyState?: string | undefined; * pause?: (() => void) | undefined; * }} T

(BaseElement, _win = self)

Source from the content-addressed store, hash-verified

87 * pause?: (() => void) | undefined;
88 * }} T */
89function createBentoElementClass(BaseElement, _win = self) {
90 if (!ExtendableHTMLElement || win !== _win) {
91 win = _win;
92 ExtendableHTMLElement = maybeWrapNativeSuper(win.HTMLElement);
93 }
94
95 return class CustomElement extends ExtendableHTMLElement {
96 /** @override */
97 constructor() {
98 super();
99
100 /**
101 * @type {import('./base-element').PreactBaseElement<T>}
102 */
103 this.implementation = new BaseElement(
104 /** @type {AmpElement} */ (/** @type {?} */ (this))
105 );
106 }
107
108 /** */
109 connectedCallback() {
110 this.classList.add('i-amphtml-built');
111 this.implementation.mountCallback();
112 this.implementation.buildCallback();
113 }
114
115 /** */
116 disconnectedCallback() {
117 this.implementation.unmountCallback();
118 }
119
120 /** @return {Promise<*>} */
121 getApi() {
122 return this.implementation.getApi();
123 }
124 };
125}
126
127/**
128 * @param {string} tag

Callers 1

defineBentoElementFunction · 0.85

Calls 1

maybeWrapNativeSuperFunction · 0.85

Tested by

no test coverage detected