Skip to content

Commit

Permalink
fix(component): add TComp generic for component load type
Browse files Browse the repository at this point in the history
  • Loading branch information
why520crazy committed Dec 17, 2020
1 parent 9a1af6a commit c53e105
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/planet/src/application/planet-application-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export interface BootstrapOptions {

export type BootstrapAppModule = (portalApp?: PlanetPortalApplication) => Promise<NgModuleRef<any>>;

export type PlantComponentFactory = <TData>(
export type PlantComponentFactory = <TData, TComp>(
componentName: string,
config: PlantComponentConfig<TData>
) => PlanetComponentRef<TData>;
) => PlanetComponentRef<TComp>;

export class PlanetApplicationRef {
public appModuleRef: NgModuleRef<any>;
Expand Down
8 changes: 6 additions & 2 deletions packages/planet/src/component/planet-component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ export class PlanetComponentLoader {
});
}

load<TData = any>(app: string, componentName: string, config: PlantComponentConfig<TData>) {
load<TData = unknown, TComp = unknown>(
app: string,
componentName: string,
config: PlantComponentConfig<TData>
): Observable<PlanetComponentRef<TComp>> {
const result = this.getPlantAppRef(app).pipe(
map(appRef => {
const componentFactory = appRef.getComponentFactory();
if (componentFactory) {
return componentFactory<TData>(componentName, config);
return componentFactory<TData, TComp>(componentName, config);
} else {
throw new Error(`${app} not registered components`);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/planet/src/component/planet-component-ref.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentRef, ElementRef } from '@angular/core';

export class PlanetComponentRef<TData = any> {
export class PlanetComponentRef<TComp = any> {
wrapperElement: HTMLElement;
componentInstance: TData;
componentRef: ComponentRef<TData>;
componentInstance: TComp;
componentRef: ComponentRef<TComp>;
dispose: () => void;
}

0 comments on commit c53e105

Please sign in to comment.