diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-11 12:28:22 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-11 12:28:22 +0200 |
commit | 8635a2c70cc24a4c52558162ac058de95750271f (patch) | |
tree | a9699b7c6696218604e6b273b4f34a6898d4f16b /client/src/app/app.module.ts | |
parent | 66dd264f7b15c05006faa00694c88c56794edc54 (diff) | |
download | PeerTube-8635a2c70cc24a4c52558162ac058de95750271f.tar.gz PeerTube-8635a2c70cc24a4c52558162ac058de95750271f.tar.zst PeerTube-8635a2c70cc24a4c52558162ac058de95750271f.zip |
Update client modules
Diffstat (limited to 'client/src/app/app.module.ts')
-rw-r--r-- | client/src/app/app.module.ts | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 7d1760fcd..8a072eaac 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -1,6 +1,10 @@ | |||
1 | import { ApplicationRef, NgModule } from '@angular/core'; | 1 | import { ApplicationRef, NgModule } from '@angular/core'; |
2 | import { BrowserModule } from '@angular/platform-browser'; | 2 | import { BrowserModule } from '@angular/platform-browser'; |
3 | import { removeNgStyles, createNewHosts } from '@angularclass/hmr'; | 3 | import { |
4 | removeNgStyles, | ||
5 | createNewHosts, | ||
6 | createInputTransfer | ||
7 | } from '@angularclass/hmr'; | ||
4 | 8 | ||
5 | import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@nglibs/meta'; | 9 | import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@nglibs/meta'; |
6 | // TODO: remove, we need this to avoid error in ng2-smart-table | 10 | // TODO: remove, we need this to avoid error in ng2-smart-table |
@@ -10,7 +14,7 @@ import 'bootstrap-loader'; | |||
10 | import { ENV_PROVIDERS } from './environment'; | 14 | import { ENV_PROVIDERS } from './environment'; |
11 | import { AppRoutingModule } from './app-routing.module'; | 15 | import { AppRoutingModule } from './app-routing.module'; |
12 | import { AppComponent } from './app.component'; | 16 | import { AppComponent } from './app.component'; |
13 | import { AppState } from './app.service'; | 17 | import { AppState, InternalStateType } from './app.service'; |
14 | 18 | ||
15 | import { AccountModule } from './account'; | 19 | import { AccountModule } from './account'; |
16 | import { CoreModule } from './core'; | 20 | import { CoreModule } from './core'; |
@@ -31,6 +35,12 @@ export function metaFactory(): MetaLoader { | |||
31 | }); | 35 | }); |
32 | } | 36 | } |
33 | 37 | ||
38 | type StoreType = { | ||
39 | state: InternalStateType, | ||
40 | restoreInputValues: () => void, | ||
41 | disposeOldHosts: () => void | ||
42 | }; | ||
43 | |||
34 | // Application wide providers | 44 | // Application wide providers |
35 | const APP_PROVIDERS = [ | 45 | const APP_PROVIDERS = [ |
36 | AppState | 46 | AppState |
@@ -67,25 +77,58 @@ const APP_PROVIDERS = [ | |||
67 | ] | 77 | ] |
68 | }) | 78 | }) |
69 | export class AppModule { | 79 | export class AppModule { |
70 | constructor(public appRef: ApplicationRef, public appState: AppState) {} | 80 | constructor( |
71 | hmrOnInit(store) { | 81 | public appRef: ApplicationRef, |
72 | if (!store || !store.state) return; | 82 | public appState: AppState |
73 | console.log('HMR store', store); | 83 | ) {} |
84 | |||
85 | public hmrOnInit(store: StoreType) { | ||
86 | if (!store || !store.state) { | ||
87 | return; | ||
88 | } | ||
89 | console.log('HMR store', JSON.stringify(store, null, 2)); | ||
90 | /** | ||
91 | * Set state | ||
92 | */ | ||
74 | this.appState._state = store.state; | 93 | this.appState._state = store.state; |
94 | /** | ||
95 | * Set input values | ||
96 | */ | ||
97 | if ('restoreInputValues' in store) { | ||
98 | let restoreInputValues = store.restoreInputValues; | ||
99 | setTimeout(restoreInputValues); | ||
100 | } | ||
101 | |||
75 | this.appRef.tick(); | 102 | this.appRef.tick(); |
76 | delete store.state; | 103 | delete store.state; |
104 | delete store.restoreInputValues; | ||
77 | } | 105 | } |
78 | hmrOnDestroy(store) { | 106 | |
79 | const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement); | 107 | public hmrOnDestroy(store: StoreType) { |
80 | // recreate elements | 108 | const cmpLocation = this.appRef.components.map((cmp) => cmp.location.nativeElement); |
109 | /** | ||
110 | * Save state | ||
111 | */ | ||
81 | const state = this.appState._state; | 112 | const state = this.appState._state; |
82 | store.state = state; | 113 | store.state = state; |
114 | /** | ||
115 | * Recreate root elements | ||
116 | */ | ||
83 | store.disposeOldHosts = createNewHosts(cmpLocation); | 117 | store.disposeOldHosts = createNewHosts(cmpLocation); |
84 | // remove styles | 118 | /** |
119 | * Save input values | ||
120 | */ | ||
121 | store.restoreInputValues = createInputTransfer(); | ||
122 | /** | ||
123 | * Remove styles | ||
124 | */ | ||
85 | removeNgStyles(); | 125 | removeNgStyles(); |
86 | } | 126 | } |
87 | hmrAfterDestroy(store) { | 127 | |
88 | // display new elements | 128 | public hmrAfterDestroy(store: StoreType) { |
129 | /** | ||
130 | * Display new elements | ||
131 | */ | ||
89 | store.disposeOldHosts(); | 132 | store.disposeOldHosts(); |
90 | delete store.disposeOldHosts; | 133 | delete store.disposeOldHosts; |
91 | } | 134 | } |