mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-01-10 12:35:07 +00:00
16 lines
615 B
TypeScript
16 lines
615 B
TypeScript
|
import { NgModuleRef, ApplicationRef } from '@angular/core';
|
||
|
import { createNewHosts } from '@angularclass/hmr';
|
||
|
|
||
|
export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
|
||
|
let ngModule: NgModuleRef<any>;
|
||
|
module.hot.accept();
|
||
|
bootstrap().then(mod => ngModule = mod);
|
||
|
module.hot.dispose(() => {
|
||
|
const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef);
|
||
|
const elements = appRef.components.map(c => c.location.nativeElement);
|
||
|
const makeVisible = createNewHosts(elements);
|
||
|
ngModule.destroy();
|
||
|
makeVisible();
|
||
|
});
|
||
|
};
|