angular-hmr icon indicating copy to clipboard operation
angular-hmr copied to clipboard

ngrx tutorial is not full

Open EugeneSnihovsky opened this issue 7 years ago • 1 comments

Hello. I spend about half of day and still can't get positive result. State data is not saved after reload. Please provide normal example of usage.

I already tried:

  1. Your repo tutorial
  2. https://medium.com/@beeman/tutorial-enable-hmr-in-angular-cli-apps-1b0d13b80130
  3. https://stackoverflow.com/a/48221333/4357871
  4. https://github.com/gdi2290/angular-hmr/pull/66#issuecomment-384275692

EugeneSnihovsky avatar Jul 16 '18 15:07 EugeneSnihovsky

Came up with this, seems to work

export function stateSetter(reducer: ActionReducer<any>): ActionReducer<any> {
  return function (state: any, action: any) {
    const NGRX_STATE = '___NGRX_STATE___';
    const newState = reducer(state, action);
    if (action.type !== '@ngrx/store/init') {
      return window[NGRX_STATE] = newState;
    } else {
      if (window[NGRX_STATE]) {
        return window[NGRX_STATE];
      }
      return newState;
    }
  };
}

export const metaReducers: MetaReducer<State>[] = !environment.production ? [storeFreeze, stateSetter] : [];

benjamin-wilson avatar Sep 02 '18 15:09 benjamin-wilson