chore(build): dependencies and config updates

This commit is contained in:
nixa 2016-09-19 16:51:05 +03:00
parent 1ba236a067
commit 04a57b7b98
11 changed files with 650 additions and 614 deletions

View file

@ -3,7 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
import { removeNgStyles, createNewHosts, createInputTransfer } from '@angularclass/hmr';
/*
* Platform and Environment providers/directives/pipes
@ -13,7 +13,7 @@ import { routing } from './app.routing';
// App is our top level component
import { App } from './app.component';
import { AppState } from './app.service';
import { AppState, InteralStateType } from './app.service';
import { GlobalState } from './global.state';
import { NgaModule } from './theme/nga.module';
import { PagesModule } from './pages/pages.module';
@ -24,6 +24,12 @@ const APP_PROVIDERS = [
GlobalState
];
type StoreType = {
state: InteralStateType,
restoreInputValues: () => void,
disposeOldHosts: () => void
};
/**
* `AppModule` is the main entry point into Angular2's bootstraping process
*/
@ -51,28 +57,37 @@ const APP_PROVIDERS = [
export class AppModule {
constructor(public appRef: ApplicationRef, public appState: AppState) {
}
hmrOnInit(store) {
hmrOnInit(store: StoreType) {
if (!store || !store.state) return;
console.log('HMR store', store);
console.log('HMR store', JSON.stringify(store, null, 2));
// set state
this.appState._state = store.state;
// set input values
if ('restoreInputValues' in store) {
let restoreInputValues = store.restoreInputValues;
setTimeout(restoreInputValues);
}
this.appRef.tick();
delete store.state;
delete store.restoreInputValues;
}
hmrOnDestroy(store) {
hmrOnDestroy(store: StoreType) {
const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
// recreate elements
// save state
const state = this.appState._state;
store.state = state;
// recreate root elements
store.disposeOldHosts = createNewHosts(cmpLocation);
// save input values
store.restoreInputValues = createInputTransfer();
// remove styles
removeNgStyles();
}
hmrAfterDestroy(store) {
hmrAfterDestroy(store: StoreType) {
// display new elements
store.disposeOldHosts();
delete store.disposeOldHosts;

View file

@ -1,8 +1,12 @@
import { Injectable } from '@angular/core';
export type InteralStateType = {
[key: string]: any
};
@Injectable()
export class AppState {
_state = { };
_state: InteralStateType = {};
constructor() {
}
@ -11,6 +15,7 @@ export class AppState {
get state() {
return this._state = this._clone(this._state);
}
// never allow mutation
set state(value) {
throw new Error('do not mutate the `.state` directly');
@ -29,8 +34,8 @@ export class AppState {
}
_clone(object) {
private _clone(object: InteralStateType) {
// simple object clone
return JSON.parse(JSON.stringify( object ));
return JSON.parse(JSON.stringify(object));
}
}

View file

@ -4,13 +4,13 @@
import { enableDebugTools, disableDebugTools } from '@angular/platform-browser';
import { enableProdMode, ApplicationRef } from '@angular/core';
// Environment Providers
let PROVIDERS = [
let PROVIDERS: any[] = [
// common env directives
];
// Angular debug tools in the dev console
// https://github.com/angular/angular/blob/86405345b781a9dc2438c0fbe3e9409245647019/TOOLS_JS.md
let _decorateModuleRef = function identity(value) { return value; };
let _decorateModuleRef = function identity<T>(value: T): T { return value; };
if ('production' === ENV) {
// Production

View file

@ -52,8 +52,8 @@ interface SystemJS {
}
interface GlobalEnvironment {
ENV;
HMR;
ENV: string;
HMR: boolean;
SystemJS: SystemJS;
System: SystemJS;
}

View file

@ -3,7 +3,6 @@
*/
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { decorateModuleRef } from './app/environment';
import { ApplicationRef } from '@angular/core';
import { bootloader } from '@angularclass/hmr';
/*
* App Module