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

Method buildCallback

src/preact/base-element.js:376–457  ·  view source on GitHub ↗

@override

()

Source from the content-addressed store, hash-verified

374
375 /** @override */
376 buildCallback() {
377 const Ctor = /** @type {typeof PreactBaseElement} */ (
378 /** @type {?} */ (this.constructor)
379 );
380
381 this.observer = new MutationObserver((rs) => this.checkMutations_(rs));
382 const {props} = Ctor;
383 const childrenInit = checkPropsFor(props, HAS_SELECTOR)
384 ? CHILDREN_MUTATION_INIT
385 : null;
386 const passthroughInit = checkPropsFor(props, HAS_PASSTHROUGH)
387 ? PASSTHROUGH_MUTATION_INIT
388 : null;
389 const templatesInit = Ctor.usesTemplate ? TEMPLATES_MUTATION_INIT : null;
390 this.observer.observe(this.element, {
391 attributes: true,
392 ...childrenInit,
393 ...passthroughInit,
394 ...templatesInit,
395 });
396
397 this.mediaQueryProps_ = checkPropsFor(props, HAS_MEDIA)
398 ? new MediaQueryProps(this.win, () => this.scheduleRender_())
399 : null;
400
401 const {staticProps} = Ctor;
402 const initProps = this.init();
403 Object.assign(this.defaultProps_, staticProps, initProps);
404
405 this.checkPropsPostMutations();
406
407 // Unmount callback.
408 subscribe(this.element, [], () => {
409 return () => {
410 this.mounted_ = false;
411 if (this.container_) {
412 // We have to unmount the component to run all cleanup functions and
413 // release handlers. The only way to unmount right now is by
414 // unrendering the DOM. If the new `unmount` API becomes available, this
415 // code can be changed to `unmount` and the follow up render would
416 // have to execute the fast `hydrate` API.
417 render(null, this.container_);
418 }
419 };
420 });
421
422 // Unblock rendering on first `CanRender` response. And keep the context
423 // in-sync.
424 subscribe(
425 this.element,
426 /** @type {import('#core/context').IContextProp<*, boolean>[]} */ ([
427 CanRender,
428 CanPlay,
429 LoadingProp,
430 ]),
431 (canRender, canPlay, loading) => {
432 this.context_.renderable = canRender;
433 this.context_.playable = canPlay;

Callers

nothing calls this directly

Calls 11

checkMutations_Method · 0.95
scheduleRender_Method · 0.95
initMethod · 0.95
checkPropsForFunction · 0.90
subscribeFunction · 0.90
assignMethod · 0.80
setReadyStateMethod · 0.80
renderFunction · 0.50
observeMethod · 0.45

Tested by

no test coverage detected