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