]>
Commit | Line | Data |
---|---|---|
1 | import { ApplicationRef, NgModule } from '@angular/core'; | |
2 | import { BrowserModule } from '@angular/platform-browser'; | |
3 | import { removeNgStyles, createNewHosts } from '@angularclass/hmr'; | |
4 | ||
5 | import { MetaModule, MetaConfig } from 'ng2-meta'; | |
6 | ||
7 | import { ENV_PROVIDERS } from './environment'; | |
8 | import { AppRoutingModule } from './app-routing.module'; | |
9 | import { AppComponent } from './app.component'; | |
10 | import { AppState } from './app.service'; | |
11 | ||
12 | import { AccountModule } from './account'; | |
13 | import { AdminModule } from './admin'; | |
14 | import { CoreModule } from './core'; | |
15 | import { LoginModule } from './login'; | |
16 | import { SharedModule } from './shared'; | |
17 | import { VideosModule } from './videos'; | |
18 | ||
19 | import { MenuComponent } from './menu.component'; | |
20 | ||
21 | const metaConfig: MetaConfig = { | |
22 | //Append a title suffix such as a site name to all titles | |
23 | //Defaults to false | |
24 | useTitleSuffix: true, | |
25 | defaults: { | |
26 | title: 'PeerTube' | |
27 | } | |
28 | }; | |
29 | ||
30 | // Application wide providers | |
31 | const APP_PROVIDERS = [ | |
32 | AppState | |
33 | ]; | |
34 | ||
35 | @NgModule({ | |
36 | bootstrap: [ AppComponent ], | |
37 | declarations: [ | |
38 | AppComponent, | |
39 | MenuComponent | |
40 | ], | |
41 | imports: [ | |
42 | BrowserModule, | |
43 | ||
44 | CoreModule, | |
45 | SharedModule, | |
46 | ||
47 | AppRoutingModule, | |
48 | ||
49 | MetaModule.forRoot(metaConfig), | |
50 | ||
51 | AccountModule, | |
52 | AdminModule, | |
53 | CoreModule, | |
54 | LoginModule, | |
55 | SharedModule, | |
56 | VideosModule | |
57 | ], | |
58 | providers: [ // expose our Services and Providers into Angular's dependency injection | |
59 | ENV_PROVIDERS, | |
60 | APP_PROVIDERS | |
61 | ] | |
62 | }) | |
63 | export class AppModule { | |
64 | constructor(public appRef: ApplicationRef, public appState: AppState) {} | |
65 | hmrOnInit(store) { | |
66 | if (!store || !store.state) return; | |
67 | console.log('HMR store', store); | |
68 | this.appState._state = store.state; | |
69 | this.appRef.tick(); | |
70 | delete store.state; | |
71 | } | |
72 | hmrOnDestroy(store) { | |
73 | const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement); | |
74 | // recreate elements | |
75 | const state = this.appState._state; | |
76 | store.state = state; | |
77 | store.disposeOldHosts = createNewHosts(cmpLocation); | |
78 | // remove styles | |
79 | removeNgStyles(); | |
80 | } | |
81 | hmrAfterDestroy(store) { | |
82 | // display new elements | |
83 | store.disposeOldHosts(); | |
84 | delete store.disposeOldHosts; | |
85 | } | |
86 | } |