Skip to content

Commit

Permalink
fix(planet-component): invoke componentRef's destroy when plantCompon…
Browse files Browse the repository at this point in the history
…entRef dispose (#270)
  • Loading branch information
why520crazy committed Feb 1, 2023
1 parent adeb49f commit 73ace3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/planet/src/component/planet-component-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ describe('PlanetComponentLoader', () => {
registerAppComponents(app1ModuleRef);
loadApp1Component(app2ModuleRef).subscribe(componentRef => {
const parent = componentRef.hostElement.parentElement;
expect(App1ProjectsComponent.state).toEqual('initialized');
componentRef.dispose();
expect(parent.innerHTML).toEqual('');
expect(App1ProjectsComponent.state).toEqual('destroyed');
});
}));
});
Expand Down
1 change: 1 addition & 0 deletions packages/planet/src/component/planet-component-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class PlanetComponentLoader {
if (appRef.viewCount > 0) {
appRef.detachView(componentRef.hostView);
}
componentRef?.destroy();
componentRootNode.remove();
};
return plantComponentRef;
Expand Down
14 changes: 12 additions & 2 deletions packages/planet/src/testing/app1.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, NgModule } from '@angular/core';
import { Component, NgModule, OnDestroy } from '@angular/core';
import { RouterModule } from '@angular/router';
import { PlanetComponentLoader } from '../component/planet-component-loader';
import { PlanetApplicationLoader } from '../application/planet-application-loader';
Expand All @@ -12,7 +12,17 @@ export const app1Name = 'app1';
projects is work
`
})
export class App1ProjectsComponent {}
export class App1ProjectsComponent implements OnDestroy {
static state: 'initialized' | 'destroyed' | '' = '';

constructor() {
App1ProjectsComponent.state = 'initialized';
}

ngOnDestroy(): void {
App1ProjectsComponent.state = 'destroyed';
}
}

@NgModule({
declarations: [App1ProjectsComponent],
Expand Down

0 comments on commit 73ace3c

Please sign in to comment.