1 import { ApplicationRef, NgModule } from '@angular/core'
2 import { BrowserModule } from '@angular/platform-browser'
7 } from '@angularclass/hmr'
9 import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
10 import 'bootstrap-loader'
12 import { ENV_PROVIDERS } from './environment'
13 import { AppRoutingModule } from './app-routing.module'
14 import { AppComponent } from './app.component'
15 import { AppState, InternalStateType } from './app.service'
17 import { AccountModule } from './account'
18 import { CoreModule } from './core'
19 import { LoginModule } from './login'
20 import { SignupModule } from './signup'
21 import { SharedModule } from './shared'
22 import { VideosModule } from './videos'
23 import { MenuComponent, MenuAdminComponent } from './menu'
24 import { HeaderComponent } from './header'
26 export function metaFactory (): MetaLoader {
27 return new MetaStaticLoader({
28 pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
29 pageTitleSeparator: ' - ',
30 applicationName: 'PeerTube',
33 description: 'PeerTube, a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser'
39 state: InternalStateType,
40 restoreInputValues: () => void,
41 disposeOldHosts: () => void
44 // Application wide providers
45 const APP_PROVIDERS = [
50 bootstrap: [ AppComponent ],
75 useFactory: (metaFactory)
78 providers: [ // expose our Services and Providers into Angular's dependency injection
83 export class AppModule {
85 public appRef: ApplicationRef,
86 public appState: AppState
89 public hmrOnInit (store: StoreType) {
90 if (!store || !store.state) {
93 console.log('HMR store', JSON.stringify(store, null, 2))
97 this.appState._state = store.state
101 if ('restoreInputValues' in store) {
102 let restoreInputValues = store.restoreInputValues
103 setTimeout(restoreInputValues)
108 delete store.restoreInputValues
111 public hmrOnDestroy (store: StoreType) {
112 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
116 const state = this.appState._state
119 * Recreate root elements
121 store.disposeOldHosts = createNewHosts(cmpLocation)
125 store.restoreInputValues = createInputTransfer()
132 public hmrAfterDestroy (store: StoreType) {
134 * Display new elements
136 store.disposeOldHosts()
137 delete store.disposeOldHosts