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'
24 export function metaFactory (): MetaLoader {
25 return new MetaStaticLoader({
26 pageTitlePositioning: PageTitlePositioning.PrependPageTitle,
27 pageTitleSeparator: ' - ',
28 applicationName: 'PeerTube',
31 description: 'PeerTube, a decentralized video streaming platform using P2P (BitTorrent) directly in the web browser'
37 state: InternalStateType,
38 restoreInputValues: () => void,
39 disposeOldHosts: () => void
42 // Application wide providers
43 const APP_PROVIDERS = [
48 bootstrap: [ AppComponent ],
69 useFactory: (metaFactory)
72 providers: [ // expose our Services and Providers into Angular's dependency injection
77 export class AppModule {
79 public appRef: ApplicationRef,
80 public appState: AppState
83 public hmrOnInit (store: StoreType) {
84 if (!store || !store.state) {
87 console.log('HMR store', JSON.stringify(store, null, 2))
91 this.appState._state = store.state
95 if ('restoreInputValues' in store) {
96 let restoreInputValues = store.restoreInputValues
97 setTimeout(restoreInputValues)
102 delete store.restoreInputValues
105 public hmrOnDestroy (store: StoreType) {
106 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
110 const state = this.appState._state
113 * Recreate root elements
115 store.disposeOldHosts = createNewHosts(cmpLocation)
119 store.restoreInputValues = createInputTransfer()
126 public hmrAfterDestroy (store: StoreType) {
128 * Display new elements
130 store.disposeOldHosts()
131 delete store.disposeOldHosts