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

Method constructor

src/chunk.js:290–339  ·  view source on GitHub ↗

* @param {!./service/ampdoc-impl.AmpDoc} ampDoc

(ampDoc)

Source from the content-addressed store, hash-verified

288 * @param {!./service/ampdoc-impl.AmpDoc} ampDoc
289 */
290 constructor(ampDoc) {
291 /** @protected @const {!./service/ampdoc-impl.AmpDoc} */
292 this.ampdoc = ampDoc;
293 /** @private @const {!Window} */
294 this.win_ = ampDoc.win;
295 /** @private @const {!PriorityQueue<Task>} */
296 this.tasks_ = new PriorityQueue();
297 /** @private @const {function(?IdleDeadline)} */
298 this.boundExecute_ = this.execute_.bind(this);
299 /** @private {number} */
300 this.durationOfLastExecution_ = 0;
301 /** @private @const {boolean} */
302 this.supportsInputPending_ = !!(
303 this.win_.navigator.scheduling &&
304 this.win_.navigator.scheduling.isInputPending
305 );
306
307 /**
308 * Set to true if we scheduled a macro or micro task to execute the next
309 * task. If true, we don't schedule another one.
310 * Not set to true if we use rIC, because we always want to transition
311 * to immeditate invocation from that state.
312 * @private {boolean}
313 */
314 this.scheduledImmediateInvocation_ = false;
315 /** @private {boolean} Whether the document can actually be painted. */
316 this.bodyIsVisible_ = this.win_.document.documentElement.hasAttribute(
317 'i-amphtml-no-boilerplate'
318 );
319
320 this.win_.addEventListener('message', (e) => {
321 if (getData(e) == 'amp-macro-task') {
322 this.execute_(/* idleDeadline */ null);
323 }
324 });
325
326 /** @protected {boolean} */
327 this.coreReady_ = false;
328 Services.viewerPromiseForDoc(ampDoc).then(() => {
329 // Once the viewer has been resolved, most of core runtime has been
330 // initialized as well.
331 this.coreReady_ = true;
332 });
333
334 ampDoc.onVisibilityChanged(() => {
335 if (ampDoc.isVisible()) {
336 this.schedule_();
337 }
338 });
339 }
340
341 /**
342 * Run fn as a "chunk".

Callers

nothing calls this directly

Calls 7

execute_Method · 0.95
schedule_Method · 0.95
getDataFunction · 0.90
addEventListenerMethod · 0.45
thenMethod · 0.45
onVisibilityChangedMethod · 0.45
isVisibleMethod · 0.45

Tested by

no test coverage detected