-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathapp.module.ts
More file actions
87 lines (80 loc) · 2.41 KB
/
Copy pathapp.module.ts
File metadata and controls
87 lines (80 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {NgModule, ApplicationRef} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {RouterModule, PreloadAllModules} from "@angular/router";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {ENV_PROVIDERS} from "./environment";
import {ROUTES} from "./app.routes";
import {AppComponent} from "./app.component";
import {CoreModule} from "./core";
import {HomeModule} from "./pages/home/home.module";
import {AuthModule} from "./pages/auth/auth.module";
import {TopModule} from "./pages/top/top.module";
import {NoContentComponent} from "./pages/no-content/no-content.component";
import {HeaderModule} from "./components/header/header.module";
import {SharedModule} from "./shared/shared.module";
import {
removeNgStyles,
createInputTransfer,
createNewHosts
} from "@angularclass/hmr";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
NoContentComponent,
],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES, {
preloadingStrategy: PreloadAllModules
}),
FormsModule,
ReactiveFormsModule,
CoreModule,
SharedModule,
HomeModule,
AuthModule,
TopModule,
HeaderModule,
],
providers: [
ENV_PROVIDERS,
]
})
export class AppModule {
constructor(public appRef: ApplicationRef) {
}
hmrOnInit(store) {
if (!store || !store.state) return;
console.log('HMR store', store);
console.log('store.state.data:', store.state.data);
// inject AppStore here and update it
// this.AppStore.update(store.state)
if ('restoreInputValues' in store) {
store.restoreInputValues();
}
// change detection
this.appRef.tick();
delete store.state;
delete store.restoreInputValues;
}
hmrOnDestroy(store) {
const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
// recreate elements
store.disposeOldHosts = createNewHosts(cmpLocation);
// inject your AppStore and grab state then set it on store
// var appState = this.AppStore.get()
store.state = {data: 'yolo'};
// store.state = Object.assign({}, appState)
// save input values
store.restoreInputValues = createInputTransfer();
// remove styles
removeNgStyles();
}
hmrAfterDestroy(store) {
// display new elements
store.disposeOldHosts();
delete store.disposeOldHosts;
// anything you need done the component is removed
}
}