aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.module.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-11 12:28:22 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-11 12:28:22 +0200
commit8635a2c70cc24a4c52558162ac058de95750271f (patch)
treea9699b7c6696218604e6b273b4f34a6898d4f16b /client/src/app/app.module.ts
parent66dd264f7b15c05006faa00694c88c56794edc54 (diff)
downloadPeerTube-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.ts67
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 @@
1import { ApplicationRef, NgModule } from '@angular/core'; 1import { ApplicationRef, NgModule } from '@angular/core';
2import { BrowserModule } from '@angular/platform-browser'; 2import { BrowserModule } from '@angular/platform-browser';
3import { removeNgStyles, createNewHosts } from '@angularclass/hmr'; 3import {
4 removeNgStyles,
5 createNewHosts,
6 createInputTransfer
7} from '@angularclass/hmr';
4 8
5import { MetaModule, MetaLoader, MetaStaticLoader, PageTitlePositioning } from '@nglibs/meta'; 9import { 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';
10import { ENV_PROVIDERS } from './environment'; 14import { ENV_PROVIDERS } from './environment';
11import { AppRoutingModule } from './app-routing.module'; 15import { AppRoutingModule } from './app-routing.module';
12import { AppComponent } from './app.component'; 16import { AppComponent } from './app.component';
13import { AppState } from './app.service'; 17import { AppState, InternalStateType } from './app.service';
14 18
15import { AccountModule } from './account'; 19import { AccountModule } from './account';
16import { CoreModule } from './core'; 20import { CoreModule } from './core';
@@ -31,6 +35,12 @@ export function metaFactory(): MetaLoader {
31 }); 35 });
32} 36}
33 37
38type StoreType = {
39 state: InternalStateType,
40 restoreInputValues: () => void,
41 disposeOldHosts: () => void
42};
43
34// Application wide providers 44// Application wide providers
35const APP_PROVIDERS = [ 45const APP_PROVIDERS = [
36 AppState 46 AppState
@@ -67,25 +77,58 @@ const APP_PROVIDERS = [
67 ] 77 ]
68}) 78})
69export class AppModule { 79export 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 }