]>
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, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@nglibs/meta'; | |
6 | import 'bootstrap-loader'; | |
7 | ||
8 | import { ENV_PROVIDERS } from './environment'; | |
9 | import { AppRoutingModule } from './app-routing.module'; | |
10 | import { AppComponent } from './app.component'; | |
11 | import { AppState } from './app.service'; | |
12 | ||
13 | import { AccountModule } from './account'; | |
14 | import { CoreModule } from './core'; | |
15 | import { LoginModule } from './login'; | |
16 | import { SharedModule } from './shared'; | |
17 | import { VideosModule } from './videos'; | |
18 | ||
19 | export function metaFactory(): MetaLoader { | |
20 | return new MetaStaticLoader({ | |
21 | pageTitlePositioning: PageTitlePositioning.PrependPageTitle, | |
22 | pageTitleSeparator: ' - ', | |
23 | applicationName: 'PeerTube', | |
24 | defaults: { | |
25 | title: 'PeerTube', | |
26 | description: 'PeerTube, a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser' | |
27 | } | |
28 | }); | |
29 | } | |
30 | ||
31 | // Application wide providers | |
32 | const APP_PROVIDERS = [ | |
33 | AppState | |
34 | ]; | |
35 | ||
36 | @NgModule({ | |
37 | bootstrap: [ AppComponent ], | |
38 | declarations: [ | |
39 | AppComponent | |
40 | ], | |
41 | imports: [ | |
42 | BrowserModule, | |
43 | ||
44 | CoreModule, | |
45 | SharedModule, | |
46 | ||
47 | AppRoutingModule, | |
48 | ||
49 | MetaModule.forRoot({ | |
50 | provide: MetaLoader, | |
51 | useFactory: (metaFactory) | |
52 | }), | |
53 | ||
54 | AccountModule, | |
55 | CoreModule, | |
56 | LoginModule, | |
57 | SharedModule, | |
58 | VideosModule | |
59 | ], | |
60 | providers: [ // expose our Services and Providers into Angular's dependency injection | |
61 | ENV_PROVIDERS, | |
62 | APP_PROVIDERS | |
63 | ] | |
64 | }) | |
65 | export class AppModule { | |
66 | constructor(public appRef: ApplicationRef, public appState: AppState) {} | |
67 | hmrOnInit(store) { | |
68 | if (!store || !store.state) return; | |
69 | console.log('HMR store', store); | |
70 | this.appState._state = store.state; | |
71 | this.appRef.tick(); | |
72 | delete store.state; | |
73 | } | |
74 | hmrOnDestroy(store) { | |
75 | const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement); | |
76 | // recreate elements | |
77 | const state = this.appState._state; | |
78 | store.state = state; | |
79 | store.disposeOldHosts = createNewHosts(cmpLocation); | |
80 | // remove styles | |
81 | removeNgStyles(); | |
82 | } | |
83 | hmrAfterDestroy(store) { | |
84 | // display new elements | |
85 | store.disposeOldHosts(); | |
86 | delete store.disposeOldHosts; | |
87 | } | |
88 | } |