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