]>
Commit | Line | Data |
---|---|---|
77d07d69 C |
1 | import { NgModuleRef, ApplicationRef } from '@angular/core' |
2 | import { createNewHosts } from '@angularclass/hmr' | |
89724816 | 3 | import { enableDebugTools } from '@angular/platform-browser' |
77d07d69 C |
4 | |
5 | export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => { | |
6 | let ngModule: NgModuleRef<any> | |
7 | module.hot.accept() | |
8 | bootstrap() | |
89724816 C |
9 | .then(mod => { |
10 | ngModule = mod | |
11 | ||
2a27c451 | 12 | const applicationRef = ngModule.injector.get(ApplicationRef) |
89724816 C |
13 | const componentRef = applicationRef.components[ 0 ] |
14 | // allows to run `ng.profiler.timeChangeDetection();` | |
15 | enableDebugTools(componentRef) | |
16 | }) | |
77d07d69 C |
17 | module.hot.dispose(() => { |
18 | const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef) | |
19 | const elements = appRef.components.map(c => c.location.nativeElement) | |
20 | const makeVisible = createNewHosts(elements) | |
21 | ngModule.destroy() | |
22 | makeVisible() | |
23 | }) | |
24 | } |