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 } 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 ],
74 useFactory: (metaFactory)
77 providers: [ // expose our Services and Providers into Angular's dependency injection
82 export class AppModule {
84 public appRef: ApplicationRef,
85 public appState: AppState
88 public hmrOnInit (store: StoreType) {
89 if (!store || !store.state) {
92 console.log('HMR store', JSON.stringify(store, null, 2))
96 this.appState._state = store.state
100 if ('restoreInputValues' in store) {
101 let restoreInputValues = store.restoreInputValues
102 setTimeout(restoreInputValues)
107 delete store.restoreInputValues
110 public hmrOnDestroy (store: StoreType) {
111 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
115 const state = this.appState._state
118 * Recreate root elements
120 store.disposeOldHosts = createNewHosts(cmpLocation)
124 store.restoreInputValues = createInputTransfer()
131 public hmrAfterDestroy (store: StoreType) {
133 * Display new elements
135 store.disposeOldHosts()
136 delete store.disposeOldHosts