-export class AppModule {
- constructor(public appRef: ApplicationRef, public appState: AppState) {}
- hmrOnInit(store) {
- if (!store || !store.state) return;
- console.log('HMR store', store);
- this.appState._state = store.state;
- this.appRef.tick();
- delete store.state;
- }
- hmrOnDestroy(store) {
- const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
- // recreate elements
- const state = this.appState._state;
- store.state = state;
- store.disposeOldHosts = createNewHosts(cmpLocation);
- // remove styles
- removeNgStyles();
- }
- hmrAfterDestroy(store) {
- // display new elements
- store.disposeOldHosts();
- delete store.disposeOldHosts;
- }
-}