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

[Angular] Move away from rxjs use for lazyloading in favor of more direct approach #1307

Merged
merged 1 commit into from Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 3 additions & 18 deletions packages/sitecore-jss-angular/src/jss-component-factory.service.ts
@@ -1,8 +1,5 @@
import { Inject, Injectable, Injector, Type, createNgModuleRef } from '@angular/core';
import { LoadChildren } from '@angular/router';
import { Inject, Injectable, Injector, Type, createNgModule } from '@angular/core';
import { ComponentRendering, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
import { of } from 'rxjs';
import { mergeMap, take } from 'rxjs/operators';
import {
ComponentNameAndModule,
ComponentNameAndType,
Expand All @@ -15,7 +12,6 @@ import {
} from './components/placeholder.token';
import { RawComponent } from './components/raw.component';
import { isRawRendering } from './components/rendering';
import { wrapIntoObservable } from './utils';

export interface ComponentFactoryResult {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -64,9 +60,9 @@ export class JssComponentFactoryService {
const lazyComponent = this.lazyComponentMap.get(component.componentName);

if (lazyComponent) {
return this.processChildren(lazyComponent.loadChildren).then((lazyChild) => {
return lazyComponent.loadChildren().then((lazyChild) => {
let componentType = null;
const moduleRef = createNgModuleRef(lazyChild, this.injector);
const moduleRef = createNgModule(lazyChild, this.injector);
const dynamicComponentType = moduleRef.injector.get(DYNAMIC_COMPONENT);
if (!dynamicComponentType) {
throw new Error(
Expand Down Expand Up @@ -115,17 +111,6 @@ export class JssComponentFactoryService {
);
}

private processChildren(loadChildren: LoadChildren): Promise<Type<unknown>> {
return wrapIntoObservable(loadChildren)
.pipe(
mergeMap((t: any) => {
return of(t);
}),
take(1)
)
.toPromise();
}

private getRawComponent(component: HtmlElementRendering): Promise<ComponentFactoryResult> {
return Promise.resolve({
componentImplementation: RawComponent,
Expand Down