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

Function createBaseCustomElementClass

src/custom-element.js:123–2152  ·  view source on GitHub ↗

* Creates a base custom element class. * * @param {!Window} win The window in which to register the custom element. * @param {function(!./service/ampdoc-impl.AmpDoc, !AmpElement, ?(typeof BaseElement))} elementConnectedCallback * @return {typeof HTMLElement}

(win, elementConnectedCallback)

Source from the content-addressed store, hash-verified

121 * @return {typeof HTMLElement}
122 */
123function createBaseCustomElementClass(win, elementConnectedCallback) {
124 if (win.__AMP_BASE_CE_CLASS) {
125 return win.__AMP_BASE_CE_CLASS;
126 }
127 const htmlElement = /** @type {typeof HTMLElement} */ (win.HTMLElement);
128
129 /**
130 * @abstract @extends {HTMLElement}
131 */
132 class BaseCustomElement extends htmlElement {
133 /** */
134 constructor() {
135 super();
136 this.createdCallback();
137 }
138
139 /**
140 * Called when elements is created. Sets instance vars since there is no
141 * constructor.
142 * @final
143 */
144 createdCallback() {
145 // Flag "notbuilt" is removed by Resource manager when the resource is
146 // considered to be built. See "setBuilt" method.
147 /** @private {boolean} */
148 this.built_ = false;
149
150 /**
151 * Several APIs require the element to be connected to the DOM tree, but
152 * the CustomElement lifecycle APIs are async. This lead to subtle bugs
153 * that require state tracking. See #12849, https://crbug.com/821195, and
154 * https://bugs.webkit.org/show_bug.cgi?id=180940.
155 * @private {boolean}
156 */
157 this.isConnected_ = false;
158
159 /** @private {?Promise} */
160 this.buildingPromise_ = null;
161
162 /**
163 * Indicates that the `mountCallback()` has been called and it hasn't
164 * been reversed with an `unmountCallback()` call.
165 * @private {boolean}
166 */
167 this.mounted_ = false;
168
169 /** @private {?Promise} */
170 this.mountPromise_ = null;
171
172 /** @private {?AbortController} */
173 this.mountAbortController_ = null;
174
175 /** @private {!ReadyState_Enum} */
176 this.readyState_ = ReadyState_Enum.UPGRADING;
177
178 /** @type {boolean} */
179 this.everAttached = false;
180

Callers 1

createCustomElementClassFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected