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'
25 export function metaFactory (): MetaLoader {
26 return new MetaStaticLoader({
27 pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
28 pageTitleSeparator: ' - ',
29 applicationName: 'PeerTube',
32 description: 'PeerTube, a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser'
38 state: InternalStateType,
39 restoreInputValues: () => void,
40 disposeOldHosts: () => void
43 // Application wide providers
44 const APP_PROVIDERS = [
49 bootstrap: [ AppComponent ],
73 useFactory: (metaFactory)
76 providers: [ // expose our Services and Providers into Angular's dependency injection
81 export class AppModule {
83 public appRef: ApplicationRef,
84 public appState: AppState
87 public hmrOnInit (store: StoreType) {
88 if (!store || !store.state) {
91 console.log('HMR store', JSON.stringify(store, null, 2))
95 this.appState._state = store.state
99 if ('restoreInputValues' in store) {
100 let restoreInputValues = store.restoreInputValues
101 setTimeout(restoreInputValues)
106 delete store.restoreInputValues
109 public hmrOnDestroy (store: StoreType) {
110 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
114 const state = this.appState._state
117 * Recreate root elements
119 store.disposeOldHosts = createNewHosts(cmpLocation)
123 store.restoreInputValues = createInputTransfer()
130 public hmrAfterDestroy (store: StoreType) {
132 * Display new elements
134 store.disposeOldHosts()
135 delete store.disposeOldHosts