npm install @angularclass/hmr
아래 처럼 app module 을 수정하면 된다는데
해보니까 되긴 되는데 이건 좀 아니다
컴포넌트 수정하면 부모의 부모의 부모...컴포넌트들을 찾아서 다 바꾸는데
결국 메인 모듈까지 바뀌더라
이게 무슨 핫리플레이스냐
import { removeNgStyles, createNewHosts, bootloader } from '@angularclass/hmr';
@NgModule({
bootstrap: [ App ],
declarations: [ App ],
imports: [
// Angular 2
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([], {
useHash: true
}),
// app
appModule
// vendors
],
providers: []
})
class MainModule {
constructor(public appRef: ApplicationRef) {}
hmrOnInit(store) {
if (!store || !store.state) return;
console.log('HMR store', store);
console.log('store.state.data:', store.state.data)
// inject AppStore here and update it
// this.AppStore.update(store.state)
if ('restoreInputValues' in store) {
store.restoreInputValues();
}
// change detection
this.appRef.tick();
delete store.state;
delete store.restoreInputValues;
}
hmrOnDestroy(store) {
var cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
// recreate elements
store.disposeOldHosts = createNewHosts(cmpLocation)
// inject your AppStore and grab state then set it on store
// var appState = this.AppStore.get()
store.state = {data: 'yolo'};
// store.state = Object.assign({}, appState)
// save input values
store.restoreInputValues = createInputTransfer();
// remove styles
removeNgStyles();
}
hmrAfterDestroy(store) {
// display new elements
store.disposeOldHosts()
delete store.disposeOldHosts;
// anything you need done the component is removed
}
}
export function main() {
return platformBrowserDynamic().bootstrapModule(MainModule)
// use `hmrModule` or the "@angularclass/hmr-loader"
.then((ngModuleRef: any) => {
// `module` global ref for webpackhmr
// Don't run this in Prod
return hmrModule(ngModuleRef, module);
});
}
// boot on document ready
bootloader(main);
'프로그램 > html' 카테고리의 다른 글
angular 10 svg component (0) | 2021.05.14 |
---|---|
angular 10 excel lib (0) | 2021.05.14 |
angular 10 observable await (0) | 2021.05.14 |
html5 indexeddb insert with promise (0) | 2021.05.14 |
html5 indexeddb table 생성 (0) | 2021.05.14 |