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 '@nglibs/meta'
10 // TODO: remove, we need this to avoid error in ng2-smart-table
11 import 'rxjs/add/operator/toPromise'
12 import 'bootstrap-loader'
14 import { ENV_PROVIDERS } from './environment'
15 import { AppRoutingModule } from './app-routing.module'
16 import { AppComponent } from './app.component'
17 import { AppState, InternalStateType } from './app.service'
19 import { AccountModule } from './account'
20 import { CoreModule } from './core'
21 import { LoginModule } from './login'
22 import { SignupModule } from './signup'
23 import { SharedModule } from './shared'
24 import { VideosModule } from './videos'
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 ],
71 useFactory: (metaFactory)
74 providers: [ // expose our Services and Providers into Angular's dependency injection
79 export class AppModule {
81 public appRef: ApplicationRef,
82 public appState: AppState
85 public hmrOnInit (store: StoreType) {
86 if (!store || !store.state) {
89 console.log('HMR store', JSON.stringify(store, null, 2))
93 this.appState._state = store.state
97 if ('restoreInputValues' in store) {
98 let restoreInputValues = store.restoreInputValues
99 setTimeout(restoreInputValues)
104 delete store.restoreInputValues
107 public hmrOnDestroy (store: StoreType) {
108 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
112 const state = this.appState._state
115 * Recreate root elements
117 store.disposeOldHosts = createNewHosts(cmpLocation)
121 store.restoreInputValues = createInputTransfer()
128 public hmrAfterDestroy (store: StoreType) {
130 * Display new elements
132 store.disposeOldHosts ()
133 delete store.disposeOldHosts