PeerTube/client/src/hmr.ts

25 lines
876 B
TypeScript
Raw Normal View History

2017-12-12 14:45:42 +01:00
import { NgModuleRef, ApplicationRef } from '@angular/core'
import { createNewHosts } from '@angularclass/hmr'
2018-09-20 14:21:57 +02:00
import { enableDebugTools } from '@angular/platform-browser'
2017-12-12 14:45:42 +01:00
export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
let ngModule: NgModuleRef<any>
module.hot.accept()
bootstrap()
2018-09-20 14:21:57 +02:00
.then(mod => {
ngModule = mod
2018-10-01 11:24:41 +02:00
const applicationRef = ngModule.injector.get(ApplicationRef)
2018-09-20 14:21:57 +02:00
const componentRef = applicationRef.components[ 0 ]
// allows to run `ng.profiler.timeChangeDetection();`
enableDebugTools(componentRef)
})
2017-12-12 14:45:42 +01:00
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()
})
}