PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
505 stars 46 forks source link

ngrx/platform how to #66

Closed Kaffiend closed 6 years ago

PatrickJS commented 6 years ago

thanks

dereklin commented 6 years ago

Just a note, I had to export stateSetter to let AOT go through in my project

Kaffiend commented 6 years ago

@dereklin im at work and cant do a PR till this evening. Can you document this in the readme. I forgot all about AOT.

On Aug 3, 2017 1:45 PM, "dereklin" notifications@github.com wrote:

Just a note, I had to export stateSetter to let AOT go through in my project

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AngularClass/angular-hmr/pull/66#issuecomment-320040908, or mute the thread https://github.com/notifications/unsubscribe-auth/AHdrNejvPRvZN42TjzkrPjs-qV6BZvHXks5sUgdCgaJpZM4Oq-va .

dereklin commented 6 years ago

@Kaffiend I am in the same boat. I am behind proxy as well. If you get to it before me, you might want to consider using this as well for tslint:

Array<ActionReducer<any, any>>
d4hines commented 6 years ago

With this approach, where does one dispatch 'SET_ROOT_STATE'? And how does one store the state in a way that persists through the hot reload?

This is what I came up with instead: store a reference to the state as global var, and use it when the app store reinitializes:


export function stateSetter(reducer: ActionReducer<any>): ActionReducer<any> {
  return function (state: any, action: any) {
    const newState = reducer(state, action);

    const NGRX_STATE = '___NGRX_STATE___';
    if (action.type !== INIT) {
      window[NGRX_STATE] = newState;
      return newState;
    }
    else {
      if (window[NGRX_STATE]) {
        return window[NGRX_STATE];
      }
      return newState;
    }
  };
}