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/platform how to #66

Merged
merged 3 commits into from Aug 2, 2017
Merged

ngrx/platform how to #66

merged 3 commits into from Aug 2, 2017

Conversation

Kaffiend
Copy link

@Kaffiend Kaffiend commented Aug 2, 2017

No description provided.

@Kaffiend Kaffiend mentioned this pull request Aug 2, 2017
@PatrickJS
Copy link
Owner

thanks

@PatrickJS PatrickJS merged commit bc9a6d2 into PatrickJS:master Aug 2, 2017
@dereklin
Copy link

dereklin commented Aug 3, 2017

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

@Kaffiend
Copy link
Author

Kaffiend commented Aug 3, 2017 via email

@dereklin
Copy link

dereklin commented Aug 3, 2017

@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
Copy link

d4hines commented Apr 25, 2018

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;
    }
  };
}

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

Successfully merging this pull request may close these issues.

None yet

5 participants