]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.module.ts
Client: add basic aot support
[github/Chocobozzz/PeerTube.git] / client / src / app / app.module.ts
CommitLineData
23bcf666 1import { ApplicationRef, NgModule } from '@angular/core';
ab32b0fc 2import { BrowserModule } from '@angular/platform-browser';
ab32b0fc
C
3import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
4
c16ce1de
C
5import { MetaModule, MetaConfig } from 'ng2-meta/src';
6import 'bootstrap-loader';
b58c69a1 7
ab32b0fc 8import { ENV_PROVIDERS } from './environment';
693b1aba 9import { AppRoutingModule } from './app-routing.module';
ab32b0fc
C
10import { AppComponent } from './app.component';
11import { AppState } from './app.service';
23bcf666 12
693b1aba
C
13import { AccountModule } from './account';
14import { AdminModule } from './admin';
15import { CoreModule } from './core';
16import { LoginModule } from './login';
17import { SharedModule } from './shared';
18import { VideosModule } from './videos';
19
b58c69a1
C
20const 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
30const 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})
61export 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}