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

fix(application-loader): remove debug logs, fix preload app load component #153

Merged
merged 5 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
All notable changes to ngx-planet will be documented in this file.

### [9.0.1-beta.6](https://github.com/worktile/ngx-planet/compare/9.0.1-beta.3...9.0.1-beta.6) (2020-12-10)


### Bug Fixes

* **application-loader:** fix preload app load component not display ([0a3abd2](https://github.com/worktile/ngx-planet/commit/0a3abd2f139bf66ed08587f87477d201414ddffa))

### [9.0.1-beta.5](https://github.com/worktile/ngx-planet/compare/9.0.1-beta.3...9.0.1-beta.5) (2020-12-10)


### Bug Fixes

* **application-loader:** fix preload app load component not display ([0a3abd2](https://github.com/worktile/ngx-planet/commit/0a3abd2f139bf66ed08587f87477d201414ddffa))

### [9.0.1-beta.4](https://github.com/worktile/ngx-planet/compare/9.0.1-beta.3...9.0.1-beta.4) (2020-12-10)


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@worktile/planet",
"version": "9.0.1-beta.4",
"version": "9.0.1-beta.6",
"description": "A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.",
"keywords": [
"micro front-end",
Expand Down
2 changes: 1 addition & 1 deletion packages/planet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@worktile/planet",
"version": "9.0.1-beta.4",
"version": "9.0.1-beta.6",
"private": false,
"peerDependencies": {
"@angular/common": "^9.0.0",
Expand Down
18 changes: 6 additions & 12 deletions packages/planet/src/application/planet-application-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { of, Observable, Subject, forkJoin, from } from 'rxjs';
import { AssetsLoader } from '../assets-loader';
import { PlanetApplication, PlanetRouterEvent, SwitchModes, PlanetOptions } from '../planet.class';
import { switchMap, share, map, tap, distinctUntilChanged, take, filter, catchError } from 'rxjs/operators';
import { getHTMLElement, coerceArray, createElementByTemplate, debug } from '../helpers';
import { getHTMLElement, coerceArray, createElementByTemplate } from '../helpers';
import { PlanetApplicationRef } from './planet-application-ref';
import { PlanetPortalApplication } from './portal-application';
import { PlanetApplicationService } from './planet-application.service';
Expand Down Expand Up @@ -224,12 +224,12 @@ export class PlanetApplicationLoader {
setTimeout(() => {
// 此处判断是因为如果静态资源加载完毕还未启动被取消,还是会启动之前的应用,虽然可能性比较小,但是无法排除这种可能性,所以只有当 Event 是最后一个才会启动
if (this.startRouteChangeEvent === event) {
this.ngZone.runOutsideAngular(() => {
forkJoin(apps$).subscribe(() => {
this.setLoadingDone();
this.ensurePreloadApps(apps);
});
// this.ngZone.runOutsideAngular(() => {
forkJoin(apps$).subscribe(() => {
this.setLoadingDone();
this.ensurePreloadApps(apps);
});
// });
}
});
} else {
Expand Down Expand Up @@ -305,7 +305,6 @@ export class PlanetApplicationLoader {
app: PlanetApplication,
defaultStatus: 'hidden' | 'display' = 'display'
): Observable<PlanetApplicationRef> {
debug(`${app.name} start bootstrap`);
this.setAppStatus(app, ApplicationStatus.bootstrapping);
const appRef = getPlanetApplicationRef(app.name);
if (appRef && appRef.bootstrap) {
Expand Down Expand Up @@ -333,7 +332,6 @@ export class PlanetApplicationLoader {
}
return result.pipe(
tap(() => {
debug(`${app.name} bootstrapped`);
this.setAppStatus(app, ApplicationStatus.bootstrapped);
if (defaultStatus === 'display' && appRootElement) {
appRootElement.removeAttribute('style');
Expand Down Expand Up @@ -437,7 +435,6 @@ export class PlanetApplicationLoader {
preload(app: PlanetApplication, directBootstrap?: boolean): Observable<PlanetApplicationRef> {
const status = this.appsStatus.get(app);
if (!status || status === ApplicationStatus.loadError) {
debug(`${app.name} start preloading`);
return this.startLoadAppAssets(app).pipe(
switchMap(() => {
if (directBootstrap) {
Expand All @@ -446,7 +443,6 @@ export class PlanetApplicationLoader {
return this.ngZone.runOutsideAngular(() => {
return this.takeOneStable().pipe(
switchMap(() => {
debug(`${app.name} start bootstrap on stable`);
return this.bootstrapApp(app, 'hidden');
})
);
Expand All @@ -468,12 +464,10 @@ export class PlanetApplicationLoader {
}),
take(1),
map(() => {
debug(`${app.name} assets is loading or app is bootstrapped, return appRef`);
return getPlanetApplicationRef(app.name);
})
);
} else {
debug(`${app.name} status is '${status}' , return appRef`);
return of(getPlanetApplicationRef(app.name));
}
}
Expand Down
10 changes: 1 addition & 9 deletions packages/planet/src/assets-loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { hashCode, isEmpty, getScriptsAndStylesFullPaths, debug } from './helpers';
import { hashCode, isEmpty, getScriptsAndStylesFullPaths } from './helpers';
import { of, Observable, Observer, forkJoin, concat, merge } from 'rxjs';
import { tap, shareReplay, map, switchMap, switchAll, concatMap, concatAll, scan, reduce } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
Expand All @@ -21,10 +21,8 @@ export class AssetsLoader {
constructor(private http: HttpClient) {}

loadScript(src: string): Observable<AssetsLoadResult> {
debug(`load '${src}' start`);
const id = hashCode(src);
if (this.loadedSources.includes(id)) {
debug(`load '${src}' successfully from cache`);
return of({
src: src,
hashCode: id,
Expand Down Expand Up @@ -76,15 +74,12 @@ export class AssetsLoader {
observer.complete();
};
document.body.appendChild(script);
debug(`load '${src}' successfully`);
});
}

loadStyle(src: string): Observable<AssetsLoadResult> {
debug(`load '${src}' start`);
const id = hashCode(src);
if (this.loadedSources.includes(id)) {
debug(`load '${src}' successfully from cache`);
return of({
src: src,
hashCode: id,
Expand Down Expand Up @@ -120,7 +115,6 @@ export class AssetsLoader {
observer.complete();
};
head.appendChild(link);
debug(`load '${src}' successfully`);
});
}

Expand Down Expand Up @@ -174,10 +168,8 @@ export class AssetsLoader {
}

loadManifest(url: string): Observable<{ [key: string]: string }> {
debug(`load '${url}' start`);
return this.http.get(url).pipe(
map((response: any) => {
debug(`load '${url}' successfully`);
return response;
})
);
Expand Down
4 changes: 1 addition & 3 deletions packages/planet/src/component/planet-component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentType, DomPortalOutlet, ComponentPortal, PortalInjector } from
import { PlanetApplicationRef } from '../application/planet-application-ref';
import { PlanetComponentRef } from './planet-component-ref';
import { PlantComponentConfig } from './plant-component.config';
import { coerceArray, debug } from '../helpers';
import { coerceArray } from '../helpers';
import { delay, map, shareReplay, finalize } from 'rxjs/operators';
import { of, Observable } from 'rxjs';
import { DOCUMENT } from '@angular/common';
Expand Down Expand Up @@ -125,7 +125,6 @@ export class PlanetComponentLoader {
if (component) {
return this.ngZone.run(() => {
const componentRef = this.attachComponent<any>(component, appRef.appModuleRef, config);
debug(`${app} component '${componentName}' loaded successfully`);
return componentRef;
});
} else {
Expand All @@ -142,7 +141,6 @@ export class PlanetComponentLoader {
}

load<TData = any>(app: string, componentName: string, config: PlantComponentConfig<TData>) {
debug(`start loading the component '${componentName}' of ${app}`);
const result = this.getPlantAppRef(app).pipe(
map(appRef => {
const componentFactory = appRef.getComponentFactory();
Expand Down
3 changes: 0 additions & 3 deletions packages/planet/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { PlanetApplication } from './planet.class';
import _debug from 'debug';

const ELEMENT_NODE_TYPE = 1;

export const debug = _debug('planet');

export function hashCode(str: string): number {
let hash = 0;
let chr: number;
Expand Down