Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: Why is Intersection Observer and requestIdleCallback not used? #129

Open
dianmonblan opened this issue Aug 11, 2022 · 0 comments

Comments

@dianmonblan
Copy link

Hello,

I think it can work like ngx-quicklink does using Intersection Observer and requestIdleCallback taking advantage of browser idle optimizing module download but now modeled to component download.

I recommend use Intersection Observer and requestIdleCallback with animationFrameScheduler for better performance on the browser.

Why is Intersection Observer and requestIdleCallback not used? Thanks for the reply and sorry for my poor english 😚

.pipe(
// This is used to coalesce changes since the `url$` subject might emit multiple values initially, e.g.
// `null` (initial value) and the url itself (when the `url` binding is provided).
// The `animationFrameScheduler` is used to prevent the frame drop.
debounceTime(0, animationFrameScheduler),
switchMap((url) => {
if (this.loadingTemplateRef) {
this.vcr.createEmbeddedView(this.loadingTemplateRef);
} else if (loadingComponent) {
const factory = this.cfr.resolveComponentFactory(loadingComponent);
this.vcr.createComponent(factory);
}
return from(
this.elementsLoaderService.loadElement(
url,
elementTag,
this.isModule,
this.importMap,
elementConfig?.hooks
)
).pipe(
catchError(() => {
this.vcr.clear();
const errorComponent =
elementConfig.errorComponent || options.errorComponent;
if (this.errorTemplateRef) {
this.vcr.createEmbeddedView(this.errorTemplateRef);
this.cdr.markForCheck();
} else if (errorComponent) {
const factory =
this.cfr.resolveComponentFactory(errorComponent);
this.vcr.createComponent(factory);
this.cdr.markForCheck();
} else if (ngDevMode) {
console.error(
`${LOG_PREFIX} - Loading of element <${elementTag}> failed, please provide <ng-template #error>Loading failed...</ng-template> and reference it in *axLazyElement="errorTemplate: error" to display customized error message in place of element`
);
}
return EMPTY;
})
);
}),
mergeMap(() => customElements.whenDefined(elementTag))
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant