Skip to content

ngrx/platform how to - #66

Merged
PatrickJS merged 3 commits into
PatrickJS:masterfrom
Kaffiend:master
Aug 2, 2017
Merged

ngrx/platform how to#66
PatrickJS merged 3 commits into
PatrickJS:masterfrom
Kaffiend:master

Conversation

@Kaffiend

@Kaffiend Kaffiend commented Aug 2, 2017

Copy link
Copy Markdown

No description provided.

@Kaffiend Kaffiend mentioned this pull request Aug 2, 2017
@PatrickJS

Copy link
Copy Markdown
Owner

thanks

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

dereklin commented Aug 3, 2017

Copy link
Copy Markdown

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

@Kaffiend

Kaffiend commented Aug 3, 2017 via email

Copy link
Copy Markdown
Author

@dereklin

dereklin commented Aug 3, 2017

Copy link
Copy Markdown

@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

d4hines commented Apr 25, 2018

Copy link
Copy Markdown

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.

5 participants