Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngrx tutorial is not full #77

Open
EugeneSnihovsky opened this issue Jul 16, 2018 · 1 comment
Open

ngrx tutorial is not full #77

EugeneSnihovsky opened this issue Jul 16, 2018 · 1 comment

Comments

@EugeneSnihovsky
Copy link

EugeneSnihovsky commented Jul 16, 2018

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. ngrx/platform how to #66 (comment)
@EugeneSnihovsky EugeneSnihovsky changed the title ngrx example is not full ngrx tutorial is not full Jul 16, 2018
@benjamin-wilson
Copy link

benjamin-wilson commented Sep 2, 2018

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] : [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants