aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.module.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-11 17:36:46 +0100
committerChocobozzz <me@florianbigard.com>2017-12-12 10:58:16 +0100
commit63c4db6d71b98523753c51747e308682d9a2e8a0 (patch)
treed26c0d092ce016f2afe56bf71b08ca4698fe673f /client/src/app/app.module.ts
parent908f6e5e38e85cc0debab0051b7fa34b13025f96 (diff)
downloadPeerTube-63c4db6d71b98523753c51747e308682d9a2e8a0.tar.gz
PeerTube-63c4db6d71b98523753c51747e308682d9a2e8a0.tar.zst
PeerTube-63c4db6d71b98523753c51747e308682d9a2e8a0.zip
Move to angular cli
Diffstat (limited to 'client/src/app/app.module.ts')
-rw-r--r--client/src/app/app.module.ts84
1 files changed, 3 insertions, 81 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts
index 1326e3411..e69edbc4b 100644
--- a/client/src/app/app.module.ts
+++ b/client/src/app/app.module.ts
@@ -1,18 +1,10 @@
1import { ApplicationRef, NgModule } from '@angular/core' 1import { NgModule } from '@angular/core'
2import { BrowserModule } from '@angular/platform-browser' 2import { BrowserModule } from '@angular/platform-browser'
3import {
4 removeNgStyles,
5 createNewHosts,
6 createInputTransfer
7} from '@angularclass/hmr'
8 3
9import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core' 4import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
10import 'bootstrap-loader'
11 5
12import { ENV_PROVIDERS } from './environment'
13import { AppRoutingModule } from './app-routing.module' 6import { AppRoutingModule } from './app-routing.module'
14import { AppComponent } from './app.component' 7import { AppComponent } from './app.component'
15import { AppState, InternalStateType } from './app.service'
16 8
17import { AccountModule } from './account' 9import { AccountModule } from './account'
18import { CoreModule } from './core' 10import { CoreModule } from './core'
@@ -35,17 +27,6 @@ export function metaFactory (): MetaLoader {
35 }) 27 })
36} 28}
37 29
38type StoreType = {
39 state: InternalStateType,
40 restoreInputValues: () => void,
41 disposeOldHosts: () => void
42}
43
44// Application wide providers
45const APP_PROVIDERS = [
46 AppState
47]
48
49@NgModule({ 30@NgModule({
50 bootstrap: [ AppComponent ], 31 bootstrap: [ AppComponent ],
51 declarations: [ 32 declarations: [
@@ -74,65 +55,6 @@ const APP_PROVIDERS = [
74 useFactory: (metaFactory) 55 useFactory: (metaFactory)
75 }) 56 })
76 ], 57 ],
77 providers: [ // expose our Services and Providers into Angular's dependency injection 58 providers: [ ]
78 ENV_PROVIDERS,
79 APP_PROVIDERS
80 ]
81}) 59})
82export class AppModule { 60export class AppModule {}
83 constructor (
84 public appRef: ApplicationRef,
85 public appState: AppState
86 ) {}
87
88 public hmrOnInit (store: StoreType) {
89 if (!store || !store.state) {
90 return
91 }
92 console.log('HMR store', JSON.stringify(store, null, 2))
93 /**
94 * Set state
95 */
96 this.appState._state = store.state
97 /**
98 * Set input values
99 */
100 if ('restoreInputValues' in store) {
101 let restoreInputValues = store.restoreInputValues
102 setTimeout(restoreInputValues)
103 }
104
105 this.appRef.tick()
106 delete store.state
107 delete store.restoreInputValues
108 }
109
110 public hmrOnDestroy (store: StoreType) {
111 const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement)
112 /**
113 * Save state
114 */
115 const state = this.appState._state
116 store.state = state
117 /**
118 * Recreate root elements
119 */
120 store.disposeOldHosts = createNewHosts(cmpLocation)
121 /**
122 * Save input values
123 */
124 store.restoreInputValues = createInputTransfer()
125 /**
126 * Remove styles
127 */
128 removeNgStyles()
129 }
130
131 public hmrAfterDestroy (store: StoreType) {
132 /**
133 * Display new elements
134 */
135 store.disposeOldHosts()
136 delete store.disposeOldHosts
137 }
138}