Skip to content

Commit

Permalink
fix(planet-component-loader): move delay to load function and replace…
Browse files Browse the repository at this point in the history
… delay with delayWhen #159
  • Loading branch information
pubuzhixing8 committed Dec 17, 2020
1 parent 6d29b75 commit d85b12c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/planet/src/component/planet-component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PlanetApplicationRef } from '../application/planet-application-ref';
import { PlanetComponentRef } from './planet-component-ref';
import { PlantComponentConfig } from './plant-component.config';
import { coerceArray } from '../helpers';
import { delay, map, shareReplay, finalize } from 'rxjs/operators';
import { of, Observable } from 'rxjs';
import { map, shareReplay, finalize, debounce, filter, take, delay, delayWhen } from 'rxjs/operators';
import { of, Observable, interval, timer } from 'rxjs';
import { DOCUMENT } from '@angular/common';
import { globalPlanet, getApplicationLoader, getApplicationService } from '../global-planet';

Expand Down Expand Up @@ -43,8 +43,6 @@ export class PlanetComponentLoader {
} else {
const app = this.applicationService.getAppByName(name);
return this.applicationLoader.preload(app, true).pipe(
// Because register use 'setTimeout',so delay 20
delay(20),
map(() => {
return globalPlanet.apps[name];
})
Expand Down Expand Up @@ -146,6 +144,14 @@ export class PlanetComponentLoader {
config: PlantComponentConfig<TData>
): Observable<PlanetComponentRef<TComp>> {
const result = this.getPlantAppRef(app).pipe(
delayWhen(appRef => {
if (appRef.getComponentFactory()) {
return of();
} else {
// Because register use 'setTimeout',so timer 20
return timer(20);
}
}),
map(appRef => {
const componentFactory = appRef.getComponentFactory();
if (componentFactory) {
Expand Down

0 comments on commit d85b12c

Please sign in to comment.